[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Selecting descendent text node
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|