[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: get the text value of a following sibling

Subject: Re: get the text value of a following sibling
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 13 Nov 2006 14:02:07 GMT
Re:  get the text value of a following sibling
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.