I am working with .Net 2.0. I found a 2002 posting with this sample
code of how to send a node-set into a XSLT transformation:
string xml = @"<foo><bar>The Test</bar></foo>";
string xsl =
@"<xsl:stylesheet xmlns:xsl=""http://www.w3.org/1999/XSL/Transform""
version=""1.0"">
<xsl:param name=""param1""/>
<xsl:template match=""/"">
bar element from param1 value:
<xsl:copy-of select=""$param1/bar""/>
</xsl:template>
</xsl:stylesheet>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XPathNavigator nav = doc.CreateNavigator();
XslTransform xslt = new XslTransform();
xslt.Load(new XmlTextReader(new StringReader(xsl)));
XPathDocument dummy = new XPathDocument(new
StringReader("<dummy/>"));
XsltArgumentList args = new XsltArgumentList();
//Pass element foo as parameter
args.AddParam("param1", "", nav.Select("/foo"));
xslt.Transform(dummy, args, Console.Out);
The output I get is:
<?xml version="1.0" encoding="Windows-1252"?>
bar element from param1 value: <bar>The Test</bar>
If I am not mistaken, I should be getting:
<?xml version="1.0" encoding="Windows-1252"?>
bar element from param1 value: The Test
Does anyone know how to fix this sample to return the correct value?
Sam Carleton