Hello, I am trying to pass a parameter through C# using a
XsltArgumentList class to a xsl:param element, but I dont know if it is
possible to do. And also I am trying to get the count of this node
too, that has as name the value of the parameter.
The "DateElementName" value is the name of a selected node that I want
to know the count on the xml file.
Any ideas? Thank you.
Dago.
I have this code:
xsl document
------------
<xsl:param name="NodeName"/>
<xsl:template match="item">
<xsl:for-each select="child::$NodeName">
<xsl:copy-of select="."/><br />
</xsl:for-each>
</xsl:template>
C# code
-------
private void Page_Load(object sender, System.EventArgs e){
string myXSLTFile = ConfigurationSettings.AppSettings.Get("XSLTFile");
string myXMLFile =
ConfigurationSettings.AppSettings.Get("RssXmlFile" );
string EleName =
ConfigurationSettings.AppSettings.Get("DateElement Name");
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath(myXMLFile));
XslTransform xslt = new XslTransform();
xslt.Load(Server.MapPath(myXSLTFile));
string DateCount = GetElementCount(EleName, doc, xslt);
this.TextBox1.Text = DateCount;
}
private string GetElementCount(string ElementName, XmlDocument XMLFile,
XslTransform XSLTFile) {
System.IO.Stream myStream = new System.IO.MemoryStream();
XPathNavigator xpathNav = XMLFile.CreateNavigator();
XsltArgumentList argsLst = new XsltArgumentList();
argsLst.AddParam("NodeName", "", ElementName);
XSLTFile.Transform(xpathNav, argsLst, myStream);
System.IO.StreamReader sr = new System.IO.StreamReader(myStream);
string output = sr.ReadToEnd();
return output;
}