Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 5th, 2014, 02:02 PM
Authorized User
Points: 151, Level: 3
Points: 151, Level: 3 Points: 151, Level: 3 Points: 151, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Default get first element whose preceding

I've the below sample xml tree.

Code:
-root
  -para
   -page
   -footnum
  -para
   -footnum
  -para
   -footnum
  -para
   -page
   -footnum
I want to apply templates on the first footnum whose preceding is page. From inside the footnum template. here below para there will be even more nodesbut here i want to apply-template only to the first footnum followed by page,, whether it is in same para or different.

The code i tried is as below.

Code:
<xsl:if test="preceding::page[1]"> 
<xsl:apply-templates select="preceding::page[1]"/>
</xsl:if>
here it is applying templates for all the footnums. please let me know where am i going wrong.

Thanks
Reply With Quote
  #2 (permalink)  
Old May 5th, 2014, 02:08 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

What you are actually testing there is if the current element has at least one page in the preceding axis.

To test if the first preceding element is a page element then test for:

preceding::*[1][self::page]
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
  #3 (permalink)  
Old May 5th, 2014, 02:22 PM
Authorized User
Points: 151, Level: 3
Points: 151, Level: 3 Points: 151, Level: 3 Points: 151, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Hi samjudson,

Thanks for the reply, this is working fine for some but not everywhere. I want something like where the match goes to root and then to the pagenum and the following first sibling footnote.

Thanks
Reply With Quote
  #4 (permalink)  
Old May 5th, 2014, 05:30 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Giving you "something like" what you want is easy. Giving you exactly what you want requires a more precise statement of requirements.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Identify element based on the element data/content ROCXY XSLT 7 September 8th, 2011 02:48 AM
How to MOVE sub-element to preceding-sibling’s last sub-element lkd XSLT 6 March 15th, 2011 11:15 AM
How to get preceding node child element value smandeh XSLT 7 June 9th, 2010 09:50 AM
Want to Pull multiple following-sibling data to preceding-sibling element sameer_kadam XSLT 4 May 9th, 2009 08:07 AM
counting the preceding cousins of an element muki XSLT 1 June 15th, 2006 02:29 AM



All times are GMT -4. The time now is 06:57 PM.


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