xsl-list
[Top] [All Lists]

RE: // and descendant interchangeable ?

2004-09-16 22:05:09
Hi,

I was under the impression that descendant:: and // are 
exactly the same.

No. "// is short for /descendant-or-self::node()/" 
<http://localhost/TR/xpath/#path-abbrev>.

I wrote this very simple stylesheet to 
extract the last occurance of the ORD element. But it doesnt 
work if I use //, instead if descendant:: is used, it works just fine.
// ends up printing 'dummy' >Ist occurance of ORD

Can somebody explain, the reason
Thanks
--sony


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns="http://www.bellsouth.com/clipwfac";
     xmlns:idm="http://www.bellsouth.com/idm"; 
exclude-result-prefixes="idm">

    <xsl:output method="xml" version="1.0" encoding="UTF-8" 
indent="yes"/>
    <xsl:template match="/">
                    <xsl:value-of select=".//idm:ORD[last()]"/>

The unabbreviated expression is

self::node()/descendant-or-self::node()/child::idm:ORD[position() = last()]

Thus, "self::node()/descendant-or-self::node()/child::idm:ORD" will select both 
ORD element nodes. The predicate "position() = last()" will be true for both 
elements, because the predicate is applied to the "child::idm:ORD" step. Thus, 
you end up with both ORD elements. xsl:value-of will then use the first one in 
document order and you end up with the dummy.

                    <xsl:value-of 
select="descendant::idm:ORD[last()]"/>

Here, on the other hand, the predicte is applied to "descendant::idm:ORD" step 
and you get the last ORD element in the document.

Cheers,

Jarno - Madam Zu: March 2004


<Prev in Thread] Current Thread [Next in Thread>