Subject: RE: recursive node checking
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 20 Feb 2006 17:12:58 -0000
|
starts-with() expects a string as its argument; if you give it a node-set
containing more than one node, XPath 1.0 will take the string value of the
first node (XPath 2.0 will throw an error).
Write select="/root/a[d[starts-with(d1, $letter)]]" />
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Andrew Smith [mailto:andrew.smith@xxxxxxxxxxxxx]
> Sent: 20 February 2006 16:47
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: recursive node checking
>
> Hello again,
>
> I'm not sure if the subject is quite correct, but what I'm
> trying to do
> is run a template on all the nodes where the 'd1's start with a given
> letter or letters, such as A or C (see the XML below).
>
> The code I currently have is as follows
>
> <xsl:variable name="letter" select="substring($string, $x, 1)" />
>
> <xsl:apply-templates select="/root/a[starts-with(d/d1, $letter)]" />
>
> $string is just a string of letters, like "AC", and using a slightly
> modified loop template I can step through it ($x is the position to
> get). The stepping is working, but it only seems to check the
> first 'd'
> node, so in the XML below it would only check the letter against 'D1',
> 'C2' and 'A4'. Is there anyway I could get it to check
> against the other
> nodes as well, since as it stands it won't select the first 'a' node
> which is should do.
>
> <root>
> <a>
> <b>Bee</b>
> <c>Cee</c>
> <d>
> <d1>D1</d1>
> </d>
> <d>
> <d1>C2</d1>
> </d>
> </a>
> <a>
> <b>Bee</b>
> <c>Cee</c>
> <d>
> <d1>C2</d1>
> </d>
> <d>
> <d1>D3</d1>
> </d>
> </a>
> <a>
> <b>Bee</b>
> <c>Cee</c>
> <d>
> <d1>A4</d1>
> </d>
> <d>
> <d1>E3</d1>
> </d>
> </a>
> </root>
>
>
> Thanks
> Andy
|