Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 30th, 2006, 12:11 PM
Registered User
 
Join Date: Aug 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to modify "for-each" to "last occurrence of" ?

Hi all,

I am currently using this code to list the values of all the topic titles in my document (used to generate a table of contents):

<xsl:for-each select="*[contains(@class,' topic/topic ')]">
      <fo:block>
    <xsl:value-of select="*[contains(@class,' topic/title ')]"/>
      </fo:block>
</xsl:for-each>

I am trying to create a variation that will only display the title from the last occurrence of the topic node instead of for all of them in the document.

How can I modify the code to specify "last occurrence of" instead of "for-each"?

TIA!

 
Old October 30th, 2006, 12:24 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Simplest change is

<xsl:for-each select="*[contains(@class,' topic/topic ')][last()]">

but you could also collapse this into the value-of, i.e.

    <fo:block>
    <xsl:value-of select="*[contains(@class,' topic/topic ')][last()]/*[contains(@class,' topic/title ')]"/>
      </fo:block>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 30th, 2006, 12:40 PM
Registered User
 
Join Date: Aug 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply Mr. Kay,

I should have been a little clearer - I am trying to get the code to retrieve the last occurrence of topic/title from when it is called. I tried to code you posted and it retrieves the last occurrence in the entire document.

In other words, when the template is called it should go UP the tree until it finds the last occurrence of topic/title and then display that value.

 
Old October 30th, 2006, 01:15 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I should know better than to respond to questions that require making wild guesses about the structure of the source document.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
count occurrence of a character in a string surya Javascript How-To 6 May 7th, 2012 04:23 PM
i want to modify the shopping ssomchai BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 April 3rd, 2008 01:52 AM
Help Modify GetThreadsRss kherrerab BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 January 22nd, 2008 12:14 PM
Modify XSLT mikeymikey XSLT 4 January 5th, 2008 11:21 PM
How to modify hidden value? Edward King Javascript 2 January 21st, 2006 05:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.