Hi,
I have an xsl as below. I am trying to loop using <xsl:for-each> and
in the select attribute of <xsl:for-each> i am getting the nodeset
from the external javascript function in the <CDATA> section.
This code works fine with MSXML4.0 parser.
When I try to use .Net, it gives me error saying " The expression
passed to this method should result in a NodeSet."
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:local1="http://csc.com/mynamespace"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:variable name="vRoot" select="/"/>
<xsl:template match="customers">
<html>
<head>
<title>Create An HTML file With An XSL Transformation</title>
</head>
<body>
<xsl:for-each select="local1:selectNodes($vRoot,'customer')">
<xsl:value-of select="."/> hello
</xsl:for-each>
</body>
</html>
</xsl:template>
<msxsl:script language="JScript" implements-prefix="local1"><![CDATA[
function selectNodes(contextNodeList,path)
{
// Added code to return current node if path string is empty
if (path == "")
{
path = ".";
}
return contextNodeList.Current.Select(path);
}
]]></msxsl:script>
</xsl:stylesheet>
---------------------- xml file ---------------
<customers>
<customer abc1="hiher" xyz="xyz">
<name>John Smith</name>
<address>123 Elm St.</address>
<phone>(123) 456-7890</phone>
</customer>
<customer>
<name>Mary Jones</name>
<address>456 Oak Ave.</address>
<phone>(156) 789-0123</phone>
</customer>
</customers>
If I change the xsl:for-each as below then it gives me the desired
result
<xsl:variable name="temp"
select="local1:selectNodes($vRoot,'customer')"/>
<xsl:for-each select="$temp">
<xsl:value-of select="."/> hello
</xsl:for-each>
I am not sure why this happens. Is there anything that I am missing ?
Appreciate your help
Thanks,
Jignesh