[xsl] Why do these xsl:variable declarations give different results?

Subject: [xsl] Why do these xsl:variable declarations give different results?
From: Steve Fogel <STEVE.FOGEL@xxxxxxxxxx>
Date: Thu, 20 Dec 2012 15:24:10 -0800 (PST)
Hi, all.

Would appreciate some help. I don't understand how these two definitions of a
variable produce different results. This is from the DITA Open Toolkit (OT).

1st alternate definition is without a condition:

<xsl:variable name="containingChapter"
     select="ancestor-or-self::*[contains(@class, ' topic/topic

2nd alternate definition is with a condition, which is me fixing a bug in the

<xsl:variable name="containingChapter">
        <xsl:when test="$hasBookParts">  <!-- The book has <part>s -->
            <xsl:copy-of select="ancestor-or-self::*[contains(@class, '
topic/topic ')][last()-1]"/>
            <xsl:copy-of select="ancestor-or-self::*[contains(@class, '
topic/topic ')][last()]"/>

Both definitions should return a <topic> element with an id attribute.
Following the definition is this statement:

<xsl:variable name="id" select="$containingChapter/@id"/>

With the first definition, the value of id is a string, as desired. With the
2nd, it's empty. Bad. Why?

For the 1st definition, the Oxygen debugger gives the value type as
"element(1)". For the 2nd, it gives the value type as "document-node(1)".  In
fact, if you look at the value of the variable in Oxygen's Nodes/Values Set
window, for the 1st definition it is:


and for the 2nd, it is:


Can someone please advise?

Many thanks!


Steve Fogel | Information Architect, Oracle Database | 650.506.4914
Oracle Server Technologies Information Development
500 Oracle Parkway | M/S 4op1126 | Redwood Shores, CA 94065

Current Thread