Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0
This is the forum to discuss the Wrox book XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition by Michael Kay; ISBN: 9780470192740
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 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 Display Modes
  #1 (permalink)  
Old November 14th, 2009, 02:52 PM
Registered User
 
Join Date: Nov 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default XSLT descendant axis problem

I have been beating my head against the wall with an XSLT issue for a couple of hours, and I clearly am lost.

I am trying to transform some XML to HTML. The relevant portion of my source XML looks like this:

Code:
  <div xml:id="sect107" type="section" n="107">
    <head>F. Indefinite Pronouns.</head>
    <p/>
    <div xml:id="sect107.1" type="subsection" n="1">
      <p/>
      [...]
    </div>
  </div>
And I have an XSL version 2.0 stylesheet that contains this template:

Code:
  <!-- match first <p> within <div> -->
  <xsl:template match="tei:div/tei:p[not(preceding-sibling::tei:p)]">
    <xsl:for-each select=".">
       <xsl:variable name="sectTop" select="ancestor::tei:div[@type='section'][1]/descendant::tei:p[1]=current()"/>
       [...]
    </xsl:for-each>
  </xsl:template>
When this template matches the second <p> tag in my XML, I am expecting the variable $sectTop to be false, but it is in fact True. This is contrary to my (limited) understanding of how XPath expressions work. Since the <p> tag in question is the second descendant of its div ancestor, and not the first, the boolean expression should evaluate as False.

Can someone kindly enlighten me as to why I am getting this unexpected result?

I am sure this problem is a result of my ignorance, but for what it is worth, I am using Saxon-PE 9.2.0.2 as my transformer.

Many thanks in advance.
Reply With Quote
  #2 (permalink)  
Old November 14th, 2009, 06:41 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

My first issue with your question is that you don't say what you want your XML output to look like, so it is hard to say if we are misunderstanding your intentions.

Firstly, I would make two templates, one matching the div, and then only processing the first p within in - this is far less intensive that using the preceding-sibling axis:

<xsl:template match="tei:div">
<xsl:apply-template select="tei:p[1]"/>
</xsl:template>

<xsl:template match="tei:div/tei:p">
[..]
</xsl:template>

I'm not sure the purpose of the <xsl:for-each> is as it does nothing.

Something like the following may work for the last part:

<xsl:variable name="sectTop" select=../../tei:div[@type='section'][1]/tei:p[1]=."/>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
The Following User Says Thank You to samjudson For This Useful Post:
sarcanon (November 14th, 2009)
  #3 (permalink)  
Old November 14th, 2009, 07:35 PM
mhkay's Avatar
Wrox Author
Points: 18,410, Level: 59
Points: 18,410, Level: 59 Points: 18,410, Level: 59 Points: 18,410, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,949
Thanks: 0
Thanked 289 Times in 284 Posts
Default

All the p elements in your example are empty, therefore they are all equal. I suspect you want the "is" operator rather than "=".
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #4 (permalink)  
Old November 14th, 2009, 09:19 PM
Registered User
 
Join Date: Nov 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by mhkay View Post
All the p elements in your example are empty, therefore they are all equal. I suspect you want the "is" operator rather than "=".
Fantastic! I know I was doing something wrong, and confusing node equality with general equality was precisely the problem.

But I don't feel too badly now seeing that comparisons take up in excess of 8 pages (!) in the XPath chapter of your fine book.

Thank you so much.
Reply With Quote
  #5 (permalink)  
Old November 14th, 2009, 09:20 PM
Registered User
 
Join Date: Nov 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you very much, but I think that Michael Kay hit the nail on the head.
Reply With Quote
Reply


Thread Tools
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
axis problem asap XSLT 3 July 31st, 2006 02:26 AM
preceding-sibling descendant xaun XSLT 3 February 28th, 2006 01:48 PM
Packages problem with WS under Axis edoardo.tosca Apache Tomcat 0 January 26th, 2006 06:17 PM
Problem in formating Y axis of Chart mayuri Crystal Reports 0 December 26th, 2005 07:15 AM
Tomcat 5 and Axis: JWS problem rushman Apache Tomcat 0 April 15th, 2005 09:30 AM



All times are GMT -4. The time now is 05:36 PM.


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