473,382 Members | 1,563 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 7179
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>...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.