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

Re: Selecting descendent text node

Subject: Re: Selecting descendent text node
From: Nick Browne <NickBrowne@xxxxxxxxxxxxxxx>
Date: Fri, 15 Sep 2000 11:36:12 +0100
xslt descendent
Mathew, at first sight you seem to have answered your own question and a possible
solution might be :
 <xsl:template match="list">
  <xsl:apply-templates select="text()" />
 </xsl:template>
 <xsl:template match="list/text()[1] | list/text()[last()]">
  <BR />First or Last: <xsl:value-of select="."/>
 </xsl:template>

This uses predicates in the template match pattern which are allowed according to
the XSLT spec.

However, looking more closely at your test, you presumably want the first (or
last) descendant at ANY level below the list element given the use of // in your
pattern. Going by Mike Kay's book, P417, para 3 there is no simple way of doing
this since the XSLT spec does not recognise (list//text())[1] as a valid pattern.

Hence Warren's suggestion, though I'm sure he meant to use // in his solution, ie.
<xsl:template match="list//text()"> as this will give your desired results. Adding
a second when element with position()=last() handles the situation where there is
only one text node.

Regards
Nick Browne
Slipstone Ltd

Matthew Bentley wrote:

> I want to select the last (or first) text node descendant of a particular
> element (lets say, list):
> To select the first text node:
> xpath=(list//text())[1]
> To select the last text node:
> xpath=(list//text())[last()]
>
> However, XSLT does not allow this kind of matching in a template match:
> Is there a way around this?
> M@


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.