Welcome to WebmasterWorld Guest from 107.20.75.63

Forum Moderators: httpwebwitch

Message Too Old, No Replies

XSLT Question

Need to select last node in a range with a value

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 13, 2002
posts:662
votes: 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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 13, 2002
posts:662
votes: 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>

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 13, 2002
posts:662
votes: 0


should change that to a call-template probably and use a name
4:33 pm on June 18, 2009 (gmt 0)

Moderator This Forum from CA 

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
posts:4059
votes: 0


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

nice one Gibble

5:17 pm on June 18, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 13, 2002
posts:662
votes: 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 June 18, 2009 (gmt 0)

Moderator This Forum from CA 

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
posts:4059
votes: 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.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members