473,382 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

loop using <xsl:for-each> and external javascript function

jd
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
Nov 12 '05 #1
2 7178
jd wrote:
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.
Well, it can't work with MSXML because of Current property and Select()
method, they are .NET-specific ones.
When I try to use .Net, it gives me error saying " The expression
passed to this method should result in a NodeSet."


Looks like that has something to do with JScript.NET. The same extension
but written in C# works just fine:

<?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="C#" implements-prefix="local1"><![CDATA[
XPathNodeIterator selectNodes(XPathNodeIterator contextNodeList,
string path)
{
// Added code to return current node if path string is empty
if (path == "")
{
path = ".";
}

return contextNodeList.Current.Select(path);

}
]]></msxsl:script>

</xsl:stylesheet>

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
jd wrote:
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.
Well, it can't work with MSXML because of Current property and Select()
method, they are .NET-specific ones.
When I try to use .Net, it gives me error saying " The expression
passed to this method should result in a NodeSet."


Looks like that has something to do with JScript.NET. The same extension
but written in C# works just fine:

<?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="C#" implements-prefix="local1"><![CDATA[
XPathNodeIterator selectNodes(XPathNodeIterator contextNodeList,
string path)
{
// Added code to return current node if path string is empty
if (path == "")
{
path = ".";
}

return contextNodeList.Current.Select(path);

}
]]></msxsl:script>

</xsl:stylesheet>

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rainer Herbst | last post by:
Hi *, please help me solving the following problem: I have an XML document containing elements like <dir:directory xmlns:dir="http://apache.org/cocoon/directory/2.0" name="pressemitteilungen"...
3
by: Rupa | last post by:
Hi, I'm trying to write an xslt to convert an email in xml format to a new xml format. <descr> <xsl:choose> <xsl:value-of select="body"> </xsl:value-of select> <xsl:when test=" <xsl:value-of...
1
by: j erickson | last post by:
with the following xsl and xml file, the display of the gif file with the <image/url> tag works. However, the gif file in the <description> tag using the name attribute "src" won't make the correct...
1
by: Michael Ahlers | last post by:
I am looking for a way to get my transformations to output a default value from <xsl:value-of/> if a selected element doesn't exist or is empty without having to have tons and tons of <xsl:choose/>...
3
by: Blaise Garant | last post by:
Hi I've made a stylesheet to transform my data into XSL-FO. This stylesheet used to work with MSXSL 4.0 but I've got some issues in ..NET. First, I changed removed all the "node-set()" function...
2
by: riceyeh | last post by:
Hi, What does <xsl:if test="not($values)"mean? What I do not understand is $values? Here, means array? And . = $value means current node is equal to the variable value? So the total meaning is...
5
by: kebabkongen | last post by:
Hi, I have an XML source which gives me the start time (in the format hh:mi) of a program and the duration of the program (in minutes). With XSLT only, I would like to generate the time the next...
4
by: C.W.Holeman II | last post by:
I am using Firefox 2.0.0.3 on MSWindows. I have an XML file http://emle.sourceforge.net/emle020000/testb.xml which invokes an XSLT file http://emle.sourceforge.net/emle020000/testb.xsl <?xml...
8
by: Hoi Wong | last post by:
With the XSLT 1.0 engine that I was forced to use, I have to parse old XML scripts where the number (to be parsed and saved into $EPISODE_NUMBER_RAW) that I want to parse is written with a comma...
6
by: Olagato | last post by:
I need to transform this: <urlset xmlns="http://www.google.com/schemas/sitemap/0.84"> <url> <loc>http://localhost/index.php/index./Paths-for-the-extreme-player</ loc> </url> <url>...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.