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 May 5th, 2014, 02:02 PM
Authorized User
 
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
 
Old May 5th, 2014, 02:08 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
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?
 
Old May 5th, 2014, 02:22 PM
Authorized User
 
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
 
Old May 5th, 2014, 05:30 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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





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





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