Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 525083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:38:05+00:00 2026-05-13T08:38:05+00:00

I am passing parameter from C# to xsl in <xsl: for each> but I

  • 0

I am passing parameter from C# to xsl in <xsl: for each> but I am not getting the output.
Here is my code till now

<xsl:param name="xpath" select="sessions/session"/>
<xsl:template match="/">
  <xsl:value-of select="$xpath"/>
  <xsl:for-each select="exsl:node-set($xpath)">

And transformed whith

XslCompiledTransform xslt = new XslCompiledTransform();
XsltArgumentList xsArgs = new XsltArgumentList();
xslt.Load(strXstFile);

//creating xpath through some logic , it is working fine 
xsArgs.AddParam("xpath", "", xpath);

MemoryStream ms = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(ms, Encoding.ASCII);
StreamReader rd = new StreamReader(ms);
xslt.Transform(doc, xsArgs, writer);

I am checking the values through and values are passing perfectly as I want but when I am using t hem in xsl:foreach it is not displaying the results I expected.Earlier when I was not using exsl:node-set it was throwing error so I used it but I guess it is making my string something else.

Any idea how to resolve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:38:05+00:00Added an answer on May 13, 2026 at 8:38 am

    I suspect that you are under the misapprehension that you can set a parameter or variable to a string and then use that string as an XPath query. You cannot.

    This:

    <xsl:param name="xpath" select="sessions/session"/>
    

    creates a parameter named xpath and sets it, by default, to a node-set. Since the context node is the root, the node-set will only contain anything if the top-level element of the input document is named sessions and it has at least one session child element.

    Here’s what $xpath doesn’t contain: an XPath expression.

    If, in your C# code, you set the parameter to a string containing an XPath expression, then instead of containing a node-set, it will contain a string. This:

    <xsl:value-of select='$xpath'/>
    

    will emit that string, and this:

    <xsl:for-each select='exsl:node-set($xpath)'>
    

    will do nothing, since the node-set function expects its argument to be a result tree fragment, and $xpath contains a string.

    I’d bet that what you really want to do is something more like this: change the name of the parameter from xpath to something less misleading, like nodeset, and create the node-set in your C# code:

    xsArgs.AddParam("nodeset", "", doc.SelectNodes(xpath));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am passing String parameter into javascript . But it is not being called.
Here is an quote from Oracle JavaEE 6 tutorial docs for passing parameter in
I'm not quite understanding how this works. Passing parameters from my entity objects works
Not parsing the parameters in the beginning but parse the input string read from
I am passing one parameter/object to the function RefValTest(object oIn) by the value but
There is a problem executing this block of code while passing the parameter. Parameter
I'm passing as parameter an id to a javascript function, because it comes from
am using CR 8.5 to generate report.I am passing a parameter field from VB
Parameter passing techniques: From what I can gather on these two techniques. Call By
The below example is got from Jon Skeet's article, Parameter passing in C# .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.