View Single Post
  #1 (permalink)  
Old November 14th, 2009, 03:52 PM
sarcanon sarcanon is offline
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:

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

  <!-- 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()"/>
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 as my transformer.

Many thanks in advance.
Reply With Quote