homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

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

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

for example
<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>

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?




 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="."/>


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

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


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

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

nice one Gibble


 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?


 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