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?
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:
creates a parameter named
xpathand 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 namedsessionsand it has at least onesessionchild element.Here’s what
$xpathdoesn’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:
will emit that string, and this:
will do nothing, since the
node-setfunction expects its argument to be a result tree fragment, and$xpathcontains a string.I’d bet that what you really want to do is something more like this: change the name of the parameter from
xpathto something less misleading, likenodeset, and create the node-set in your C# code: