Re: [xsl] get the text value of a following sibling

Subject: Re: [xsl] get the text value of a following sibling
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 13 Nov 2006 14:02:07 GMT
A stylesheet with (just) the two templates

<xsl:template match="a">

<xsl:template match="br">
 <xsl:text>: </xsl:text>

should do what you want.

To coment on your code sample

 <xsl:value-of select="text()"/>

It's best to use . rather than text() here as text() will (in xslt 1)
just select the first text node child of a so if there are any comments
for example, you lose any text after the comment,

 <xsl:value-of select="following-sibling::*[2]/text()"/>

In your poseed input, typically an a element has two following br
elments so following-sibling::*[2] is teh second of those br and then
/text() selects the (empty) node set of children of the br.

> It only outputs the text in the <a> tag 
just a comment on terminology the content of the a tag is 'a href="..."'
you mean the text between the tags <a> and </a> but XSLT does not have
any access to the tags in the document.

>  How should I treat that text? Isn't it considered as a node?
yes it is a node, but as shown above you were looking in the br element
rather than at sibling nodes of the a. It's simpler just to process it
all from the parent element as shown with the templates above rather
than for-each over the a and then pick up the related nodes.


Current Thread