[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: // and descendant interchangeable ?

Subject: RE: // and descendant interchangeable ?
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Fri, 17 Sep 2004 08:05:09 +0300
descendant xsl
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.