The following transformation puzzles me when trying to transform XML to XML.
I get an exception "THE EXPRESSION PASSED TO THIS METHOD SHOULD RESULT IN A
NODESET" at the last line "xmlDoc.Load(xr)" when I run the code.
I previously tried it all without a parameter and hard-coded the value into
the 'apply-templates' statement and the tranform produced
the result that I expected but when I inset the parameter I get the
exception.
I would appreciate it if someone could look over the code and identify which
part of the code causes the fault
I use VB.NET 2003 and .NET 1.1
cheers,
Craig
------------------ regs.xml ------------
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="regs.xslt"?>
<AllCtls>
<Ctl>
<cl>2</cl>
<ol>AAAAAAAAA</ol>
</Ctl>
<Ctl>
<cl>6</cl>
<ol>BBBBBBBBB</ol>
</Ctl>
<Ctl>
<cl>3</cl>
<ol>CCCCCCCCC</ol>
</Ctl>
<Ctl>
<cl>6</cl>
<ol>DDDDDDDDD</ol>
</Ctl>
</AllCtls>
------------ regs.xslt -------------------
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:param name='myFilter' />
<xsl:template match="/">
<AllCtls>
<xsl:apply-templates select='$myFilter' />
</AllCtls>
</xsl:template>
<xsl:template match="Ctl">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
----------- VB.Net code ----------------
Dim xmlDoc As New XmlDocument
xmlDoc.Load("regs.xml")
Dim xslt As XslTransform = New XslTransform
xslt.Load("regs.xslt")
Dim xslArg As XsltArgumentList = New XsltArgumentList
Dim str As String = "/AllCtls/Ctl[cl='6']"
xslArg.AddParam("myFilter", "", str)
Dim res As XmlResolver
Dim nav As XPathNavigator = xmlDoc.CreateNavigator()
Dim xr As XmlReader = xslt.Transform(nav, xslArg, res)
Dim xmlDoc As New XmlDocument
xmlDoc.Load(xr)
------------------------------------------------------------