473,327 Members | 1,930 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,327 software developers and data experts.

XPathNodeIterator bahaviour

Hi,

please clarify this doubt about XPathNodeIterator..the following XSLT uses this..

my doubt is, by looking at the XSLT, i thought the output to be Book1..but the actual output is Book1Book2Book3Book4..

as I understand, func method is called only once and XPathNodeIterator.MoveNext() is called only once..and how is this concatenated output??

tia,
avnrao.

XSLT :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:books"
exclude-result-prefixes="msxsl">

<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

<xsl:variable name="node-fragment">
<book>Book1</book>
<book>Book2</book>
<book>Book3</book>
<book>Book4</book>
</xsl:variable>

<msxsl:script implements-prefix="user" language="c#">
-- include cdata here
string func(XPathNodeIterator it)
{
it.MoveNext();
return it.Current.Value;
//it.Current returns XPathNavigator positioned on the current node
}
</msxsl:script>
<xsl:template match="/">
<books>
<xsl:value-of select="user:func(msxsl:node-set($node-fragment))"/>
</books>
</xsl:template>

</xsl:stylesheet>

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>Hle4+hLykkifd3FHHowmXA==</Id>
Nov 12 '05 #1
2 3554
avnrao via .NET 247 wrote:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:books"
exclude-result-prefixes="msxsl">

<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

<xsl:variable name="node-fragment">
<book>Book1</book>
<book>Book2</book>
<book>Book3</book>
<book>Book4</book>
</xsl:variable>

<msxsl:script implements-prefix="user" language="c#">
-- include cdata here
string func(XPathNodeIterator it)
{
it.MoveNext();
return it.Current.Value;
//it.Current returns XPathNavigator positioned on the current node
}
</msxsl:script>
<xsl:template match="/">
<books>
<xsl:value-of select="user:func(msxsl:node-set($node-fragment))"/>


Result tree fragment ($node-fragment) is treated as a tree with
artificial root node and fragment nodes as its children.
msxsl:node-set() function always returns that root node.

Use <xsl:value-of select="user:func(msxsl:node-set($node-fragment)/*)"/>

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
avnrao via .NET 247 wrote:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:books"
exclude-result-prefixes="msxsl">

<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

<xsl:variable name="node-fragment">
<book>Book1</book>
<book>Book2</book>
<book>Book3</book>
<book>Book4</book>
</xsl:variable>

<msxsl:script implements-prefix="user" language="c#">
-- include cdata here
string func(XPathNodeIterator it)
{
it.MoveNext();
return it.Current.Value;
//it.Current returns XPathNavigator positioned on the current node
}
</msxsl:script>
<xsl:template match="/">
<books>
<xsl:value-of select="user:func(msxsl:node-set($node-fragment))"/>


Result tree fragment ($node-fragment) is treated as a tree with
artificial root node and fragment nodes as its children.
msxsl:node-set() function always returns that root node.

Use <xsl:value-of select="user:func(msxsl:node-set($node-fragment)/*)"/>

--
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

1
by: panik | last post by:
Hi, say I have an xml file with an X number of nodes I want to loop through (to, for example, display each node as a HyperLink in an asp.net webpage). Which of both is best practice: 1. Loop...
0
by: Ilian Nilsson | last post by:
Hi Al If I try to use the following code lines in an recursive (recurse down in Xml tree) manner the XPathNodeIterator gets reset in it's parent method call, which will end up in that all nodes...
0
by: avnrao via .NET 247 | last post by:
Hi, please clarify this doubt about XPathNodeIterator..the following XSLT uses this.. my doubt is, by looking at the XSLT, i thought the output to be Book1..but the actual output is...
2
by: Emmanuel | last post by:
Hi, I am writing an ASP.NET web applications which uses an xml file to display html content on the web pages. My problem is that using the Value property of the current object of the...
4
by: Jamie da Silva | last post by:
I couldn't find a better resource for reporting a possible .NET Framework 1.1 (SP0 & 1) bug, so if this is not the proper forum, please let me know. The problem appears to occur when using...
3
by: KJ | last post by:
It is true that there is no way to get the outerXml of XPathNodeIterator.Current? Please say it isn't so.
0
by: David | last post by:
I'm using an XPathNodeIterator to select an element in an XML document that contains text I am going to put in a label on an aspx page. I want to be able to include HTML tags in the text read from...
2
by: Volkan | last post by:
Hi, I'm trying to compare two XML documents and i'm using XPath queries to select nodes. XPathNavigator's Select method runs fast enough and returns an XPathNodeIterator object. When i try to...
6
by: Kindler Chase | last post by:
I'm trying to iterate through a set of nodes and then edit/delete specific attributes using XPathNodeIterator. Adding attributes is no problem. My first question is how do I delete an attribute...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.