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

node-sets not sent to xslt extension object correctly

Here's what I have (in snippets)
** XML **
<parent>
<child>
<grandchild/>
</child>
</parent>

** XSLT **
<xsl:template match="/parent">
parent: <xsl:value-of select="util:LocalName(.)"/>
child: <xsl:value-of select="util:LocalName(child)"/>
grandchild: <xsl:value-of select="util:LocalName(child/grandchild)"/>
</xsl:template>

** C# (util object) **
public string LocalName(XmlPathNodeIterator xit)
{
return xit.Current.LocalName;
}

but for some reason, each call to LocalName returns "parent". A little
sleuthing, and I've discovered that the XmlPathNodeIterators _are_
different: they seem to have different FilterQuery and ChildrenQuery
internal settings, but how do I translate that into something I can have
access to?

Thanks,
Douglas R. Steen
Boulder, CO
Nov 12 '05 #1
5 2854
Douglas Steen wrote:
public string LocalName(XmlPathNodeIterator xit)
{
return xit.Current.LocalName;
}


You have to call MoveNext() on XPathNodeIterator each time you want next
node:

public string LocalName(XPathNodeIterator xit)
{
if (xit.MoveNext())
return xit.Current.LocalName;
else
return "";
}

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
Thanks, Oleg, but when I try that with the first example (XSLT:
select="util:LocalName(.)") it returns false and .Current becomes null.
It's as if, in the first example, the iterator has already been "moved". Is
it that calling the extension object with (.) sends the XPathNodeIterator
with a single node, whereas calling it with (child) sends a nodeset? If so,
is there a way of telling that MoveNext is going to move me off the end of
the set, before I move? (Or, even better, changing my XSLT so that I can be
sure that a single node is sent? I've tried /child[0] and /child/node() to
no avail.)

Thanks alot for the help.

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:un****************@TK2MSFTNGP11.phx.gbl...
Douglas Steen wrote:
public string LocalName(XmlPathNodeIterator xit)
{
return xit.Current.LocalName;
}


You have to call MoveNext() on XPathNodeIterator each time you want next
node:

public string LocalName(XPathNodeIterator xit)
{
if (xit.MoveNext())
return xit.Current.LocalName;
else
return "";
}

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #3
Douglas Steen wrote:
Thanks, Oleg, but when I try that with the first example (XSLT:
select="util:LocalName(.)") it returns false and .Current becomes null.
It's as if, in the first example, the iterator has already been "moved". Is
it that calling the extension object with (.) sends the XPathNodeIterator
with a single node, whereas calling it with (child) sends a nodeset? If so,
is there a way of telling that MoveNext is going to move me off the end of
the set, before I move? (Or, even better, changing my XSLT so that I can be
sure that a single node is sent? I've tried /child[0] and /child/node() to
no avail.)


Sorry, I can't reproduce the problem. Here is the stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:util="urn:my-scripts">
<msxsl:script language="C#" implements-prefix="util"><![CDATA[
public string LocalName(XPathNodeIterator xit)
{
return xit.MoveNext()? xit.Current.LocalName : "";
}
]]>
</msxsl:script>
<xsl:template match="/parent">
parent: <xsl:value-of select="util:LocalName(.)"/>
child: <xsl:value-of select="util:LocalName(child)"/>
grandchild: <xsl:value-of select="util:LocalName(child/grandchild)"/>
</xsl:template>
</xsl:stylesheet>

When applied to your XML it outputs:

parent: parent
child: child
grandchild: grandchild

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #4
I'm using a rather complicated extension object (rather than doing it
inline), and in simplifying for this post, I may have gone too far. I used
your example and got the same results, but when I tried to add some of the
initial complexity, I ran into the problem again. While the example below
works, this one doesn't:

<xsl:template match="/parent">
<xsl:for-each select="child">
parent: <xsl:value-of select="util:LocalName(../parent)"/>
child: <xsl:value-of select="util:LocalName(.)"/>
grandchild: <xsl:value-of select="util:LocalName(./grandchild)"/>
</xsl:for-each>
</xsl:template>

Thoughts?

Thanks for taking the time on this
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:OC**************@TK2MSFTNGP10.phx.gbl...
Douglas Steen wrote:
Thanks, Oleg, but when I try that with the first example (XSLT:
select="util:LocalName(.)") it returns false and .Current becomes null.
It's as if, in the first example, the iterator has already been "moved". Is it that calling the extension object with (.) sends the XPathNodeIterator with a single node, whereas calling it with (child) sends a nodeset? If so, is there a way of telling that MoveNext is going to move me off the end of the set, before I move? (Or, even better, changing my XSLT so that I can be sure that a single node is sent? I've tried /child[0] and /child/node() to no avail.)


Sorry, I can't reproduce the problem. Here is the stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:util="urn:my-scripts">
<msxsl:script language="C#" implements-prefix="util"><![CDATA[
public string LocalName(XPathNodeIterator xit)
{
return xit.MoveNext()? xit.Current.LocalName : "";
}
]]>
</msxsl:script>
<xsl:template match="/parent">
parent: <xsl:value-of select="util:LocalName(.)"/>
child: <xsl:value-of select="util:LocalName(child)"/>
grandchild: <xsl:value-of select="util:LocalName(child/grandchild)"/>
</xsl:template>
</xsl:stylesheet>

When applied to your XML it outputs:

parent: parent
child: child
grandchild: grandchild

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #5
On a hunch, I tried this:

<xsl:template match="/parent">
<xsl:variable name="parentNode" select="."/>
<xsl:for-each select="child">
parent: <xsl:value-of select="util:LocalName($parentNode)"/>
child: <xsl:value-of select="util:LocalName(.)"/>
grandchild: <xsl:value-of select="util:LocalName(./grandchild)"/>
</xsl:for-each>
</xsl:template>

and it _does_ work. Whereas calling the parent directly (..) doesn't?

Alright, now I've got something I can use; thanks for all your help. If you
(or anyone else) wants to clear up what's going on here, I'd love to
understand this better, but I can move forward now & I thank you.

"Douglas Steen" <du*@pobox.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I'm using a rather complicated extension object (rather than doing it
inline), and in simplifying for this post, I may have gone too far. I used your example and got the same results, but when I tried to add some of the
initial complexity, I ran into the problem again. While the example below
works, this one doesn't:

<xsl:template match="/parent">
<xsl:for-each select="child">
parent: <xsl:value-of select="util:LocalName(../parent)"/>
child: <xsl:value-of select="util:LocalName(.)"/>
grandchild: <xsl:value-of select="util:LocalName(./grandchild)"/>
</xsl:for-each>
</xsl:template>

Thoughts?

Thanks for taking the time on this
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:OC**************@TK2MSFTNGP10.phx.gbl...
Douglas Steen wrote:
Thanks, Oleg, but when I try that with the first example (XSLT:
select="util:LocalName(.)") it returns false and .Current becomes null. It's as if, in the first example, the iterator has already been
"moved".
Is it that calling the extension object with (.) sends the XPathNodeIterator with a single node, whereas calling it with (child) sends a nodeset?
If
so, is there a way of telling that MoveNext is going to move me off the
end
of the set, before I move? (Or, even better, changing my XSLT so that I can be sure that a single node is sent? I've tried /child[0] and
/child/node()
to no avail.)


Sorry, I can't reproduce the problem. Here is the stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:util="urn:my-scripts"> <msxsl:script language="C#" implements-prefix="util"><![CDATA[
public string LocalName(XPathNodeIterator xit)
{
return xit.MoveNext()? xit.Current.LocalName : "";
}
]]>
</msxsl:script>
<xsl:template match="/parent">
parent: <xsl:value-of select="util:LocalName(.)"/>
child: <xsl:value-of select="util:LocalName(child)"/>
grandchild: <xsl:value-of select="util:LocalName(child/grandchild)"/>
</xsl:template>
</xsl:stylesheet>

When applied to your XML it outputs:

parent: parent
child: child
grandchild: grandchild

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com


Nov 12 '05 #6

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

Similar topics

8
by: J Peterman | last post by:
Im having a nightmare trying to understand these nodes and linked lists. I've posted my code for my node.h, node.cpp, linkedlist.h and linkedlist.cpp files in separates replies. Can someone...
6
by: Chuck | last post by:
What's the difference between using "catalog node" and catalog admin node"? -- Chuck Remove "_nospam" to reply by email
3
by: stabbert | last post by:
We are running DB2 UDB 8.1.6 in a partitioned environment where we have 8 physical nodes. We have a process that remotely connects to each individual node and loads some data. By setting the...
3
by: Francois Grieu | last post by:
Given that next is the first field in struct node, and head is a pointer to node, does assigning ((node*)&head)->next safely assign head ? Illustration (this code works on many platforms)...
5
by: Jeroen Ceuppens | last post by:
I need to put a new node at the end of the tree, that end is not te lowest in de list but the deepest (the one with the most + before it) Node A Node 1 Node 2 Node 3 Node 4: Deepest Node B:...
3
by: Saradhi | last post by:
Hi All, Here I am facing a performance problem with the TreeView Node renaming. I am displaying a hierarchy Data in a treeview in my Windows C# Application. My tree view represents an...
5
by: poldoj | last post by:
Hi all, I have a treenode control and I would like to add a node in a certain level as child. For example I know that with this code I can add a level one node plus a level two node: ...
9
by: Moses | last post by:
Hi All, How to check weather a node has sibling? Is there any function like " hasChildNodes() " Thanks in Advance Moses
3
by: Kane | last post by:
When you create node 1 you allocate memory and link it Again when you create node 2 you would allocate memory for that node in a different section of the code. Is there more efficient way where I...
4
by: matth | last post by:
I've been working on something that deals with handling a user's selection within the DOM and I'm tripping up on one last, but crucial, detail. Forgive me for the length of the code, but my...
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
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: 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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.