RE: [xsl] recursive node checking

Subject: RE: [xsl] recursive node checking
From: "Andrew Smith" <andrew.smith@xxxxxxxxxxxxx>
Date: Tue, 21 Feb 2006 09:28:22 -0000
Thanks for this, it worked a treat, I'm getting what I wanted now.
Thanks a lot again :-)

-----Original Message-----
From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
Sent: 20 February 2006 17:13
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] recursive node checking

starts-with() expects a string as its argument; if you give it a
containing more than one node, XPath 1.0 will take the string value of
first node (XPath 2.0 will throw an error).

Write select="/root/a[d[starts-with(d1, $letter)]]" />

Michael Kay

-----Original Message-----
From: David Carlisle [mailto:davidc@xxxxxxxxx]
Sent: 20 February 2006 17:02
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] recursive node checking

> but it only seems to check the first 'd' node,

  d/d1 selects a node set of all the d1 children, but if you use a node
set in a string context then (in XSLT1) it uses the string value of the
first node in document order, and silently discards the other nodes. (In
XSLT2 it's an error, unless backwards compatibility is enabled)

starts-with requires two strings as arguments so in
starts-with(d/d1, $letter)
the first argument is the string value of the first node
selected by d/d1.
You need to arrange that the node set pased to starts-with has at most
one node, so something like

select="/root/a[d/d1[starts-with(., $letter)]]"
selects all a elements that have a d1 grandchild that starts with

Note its a bit confusing to call the top level element root in an xpath
context, as the root node is the parent of that element not the element


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

Current Thread