xsl-list
[Top] [All Lists]

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

2006-11-13 07:03:00

A stylesheet with (just) the two templates

<xsl:template match="a">
 <xsl:text>&#10;</xsl:text>
 <xsl:apply-templates/.
</xsl:template>

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


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.

David


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>