homepage Welcome to WebmasterWorld Guest from 54.204.58.87
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
XSLT Question
Need to select last node in a range with a value
Gibble




msg:3936083
 4:20 pm on Jun 18, 2009 (gmt 0)

for example
<items>
<item name="F1">joe</item>
<item name="F2">smith</item>
<item name="F3">5</item>
<item name="F4">4</item>
<item name="F5">3</item>
<item name="F7" />
<item name="F9">foo</item>
</items>

I need to be able to select the last value between items "F3" and "F8" that has a value, in this case <item name="F5">3</item>.

How would I write that in an XSLT?

Thanks.

 

Gibble




msg:3936100
 4:30 pm on Jun 18, 2009 (gmt 0)

Got it, I think

<xsl:apply-templates select="node()[substring-after(name(),'F') &lt; 9 and substring-after(name(),'F') &gt; 2 and .!= '']" />

<xsl:template match="node()[substring-after(name(),'F') &lt; 9 and substring-after(name(),'F') &gt; 2]">
<xsl:if test="position() = last()">
<xsl:value-of select="."/>
</xsl:if>
</xsl:template>

Gibble




msg:3936101
 4:30 pm on Jun 18, 2009 (gmt 0)

should change that to a call-template probably and use a name

httpwebwitch




msg:3936106
 4:33 pm on Jun 18, 2009 (gmt 0)

you've got it.
position() and last() do the trick

nice one Gibble

Gibble




msg:3936140
 5:17 pm on Jun 18, 2009 (gmt 0)

I presume the template was needed to create a "set", but is there a way to have written it without it?

httpwebwitch




msg:3936380
 11:43 pm on Jun 18, 2009 (gmt 0)

I suppose you could use the same XPATH in an <xsl:for-each>.

Have you tried combining the "node()[substring-after(name(),'F' ..." part with the position() and last() comparison? Maybe you could do the whole thing in one complex expression.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved