Page 1 of 1

XSLT descendant axis problem

Posted: Sat Nov 14, 2009 10:02 pm
by sarcanon
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: Select all

  <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: Select all

  <!-- 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 Oxygen XML 11 (build 2009100911) and Saxon-PE 9.2.0.2 as my transformer.

Many thanks in advance.

Re: XSLT descendant axis problem

Posted: Sun Nov 15, 2009 8:48 pm
by sarcanon
In case anyone is interested, it was kindly pointed out to me in another forum that I was using the wrong comparison operator.

I should have been using "is" rather than "=", since I was intending to compare nodes and not element values.