Subject: Re: Selecting descendent text node From: Nick Browne <NickBrowne@xxxxxxxxxxxxxxx> Date: Fri, 15 Sep 2000 11:36:12 +0100 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Selecting descendent text node, Warren Hedley | Thread | format-number in XT, Larry_Mason |
RE: Problem with ignoring system ID, Paul Terray | Date | Re: My favourite XSLT enhancement r, David Carlisle |
Month |