[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] recursive node checking


Subject: [xsl] recursive node checking
From: "Andrew Smith" <andrew.smith@xxxxxxxxxxxxx>
Date: Mon, 20 Feb 2006 16:47:01 -0000

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


Current Thread
Keywords
xml