This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: nodeset extension in .Net?
- From: "Kirk Allen Evans" <kaevans at xmlandasp dot net>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 6 Aug 2002 09:26:05 -0400
- Subject: RE: [xsl] nodeset extension in .Net?
- Organization: Your Name Here
- Reply-to: xsl-list at lists dot mulberrytech dot com
> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of bryan
> Sent: Monday, August 05, 2002 4:55 AM
> To: xsl-list@lists.mulberrytech.com
> Subject: [xsl] nodeset extension in .Net?
>
>
>
> I seem to remember that in .Net there isn't a node-set extension
> function, and that node-sets are accessible. Does anyone know if this is
> correct, cause I'm getting some results here that lead me to conclude
> that I need a node-set() function and can't just merrily run an xpath
> against my parameter.
Here is a sample stylesheet that accepts a node set as a parameter.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" version="1.0" indent="yes"/>
<xsl:param name="state_list" select="/.."/>
<xsl:template match="/">
<states>
<names>
<xsl:apply-templates select="$state_list/descr"/>
</names>
<capitals>
<xsl:apply-templates select="$state_list/capital"/>
</capitals>
</states>
</xsl:template>
<xsl:template match="descr">
<description>
<xsl:value-of select="."/>
</description>
</xsl:template>
<xsl:template match="capital">
<capital_city>
<xsl:value-of select="."/>
</capital_city>
</xsl:template>
</xsl:stylesheet>
The .NET code to pass a parameter:
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("test.xml"));
XmlDocument stateDoc = new XmlDocument();
stateDoc.Load(Server.MapPath("states.xml"));
System.Xml.XPath.XPathNavigator nav = stateDoc.CreateNavigator();
System.Xml.XPath.XPathNodeIterator iter = nav.Select("/states/state");
XslTransform trans = new XslTransform();
trans.Load(Server.MapPath("test.xslt"));
XsltArgumentList args = new XsltArgumentList();
args.AddParam("state_list",String.Empty,iter);
Response.ContentType = "text/xml";
trans.Transform(doc,args,Response.OutputStream);
states.xml:
<?xml version="1.0" encoding="utf-8" ?>
<states>
<state>
<abbrev>GA</abbrev>
<descr>Georgia</descr>
<capital>Atlanta</capital>
</state>
<state>
<abbrev>TN</abbrev>
<descr>Tennessee</descr>
<capital>Nashville</capital>
</state>
<state>
<abbrev>AL</abbrev>
<descr>Alabama</descr>
<capital>Montgomery</capital>
</state>
</states>
test.xml:
<?xml version="1.0" encoding="utf-8" ?>
<root/>
Kirk Allen Evans
http://www.xmlandasp.net
"XML and ASP.NET", New Riders Publishing
http://www.amazon.com/exec/obidos/ASIN/073571200X
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list