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

Re: Re: limiting preceding axis by ancestor

Subject: Re: Re: limiting preceding axis by ancestor
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 8 May 2002 00:46:16 -0700 (PDT)
preceding axis xml
Joerg Heinicke <joerg dot heinicke at gmx dot de> wrote:

> The [1] is implicit and not needed, because generate-id() on a 
> nodeset returns the id of the first element in this nodeset. I wrote 
> it for maybe better understanding.
> 
> <xsl:if test=". = preceding::bar[generate-id(ancestor::foo[1]) = 
> generate-id(current()/ancestor::foo[1])]">

This is one case where the established belief that 

generate-id(someXPathExpression) = generate-id(someXPathExpression[1])

is *not* true.

This is clearly not so, because "ancestor" is a reverse axis.

generate-id(ancestor::foo[1]) 

will be applied on the nearest ancesstor (the last in document order)

while

generate-id(ancestor::foo)

will be applied on the outermost ancestor (the first in document
order).


Here's a small example illustrating this (I'm using the "preceding"
axis here, as I have a suitable xml file at hand):

The source xml is:

testxp17.xml:
------------
<groups>
    <group>
        <tables>
            <table index="1" />
            <table index="2" />
        </tables>
        <views>
            <view index="3" />
            <view index="4" />
        </views>
    </group>
    <group>
        <tables>
            <table index="1" />
        </tables>
        <views>
            <view index="1" />
        </views>
    </group>
</groups>


The transformation is:

<xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>
  <xsl:template match="/">
    <xsl:variable name="vlastView" select="(//view)[last()]"/>
    <xsl:variable name="vID1" 
         select="generate-id($vlastView/preceding::tables[1])"/>
    <xsl:variable name="vID2" 
         select="generate-id($vlastView/preceding::tables)"/>


    <xsl:value-of 
    select="concat('generate-id($vlastView/preceding::tables[1]) = '
                                 , $vID1
                                 , '&#xA; '
                                 )"/>
    <xsl:value-of 
    select="concat('generate-id($vlastView/preceding::tables) = '
                                 , $vID2
                                 , '&#xA;' 
                                 )"/>
                                 
    <xsl:value-of select="concat('(gID1 = gID2) = ', $vID1 = $vID2)"/>
  </xsl:template>
</xsl:stylesheet> 


The results are:

1. with Saxon:

generate-id($vlastView/preceding::tables[1]) = d0e22
 generate-id($vlastView/preceding::tables) = d0e5
(gID1 = gID2) = false


2. with MSXML4:

generate-id($vlastView/preceding::tables[1]) = IDANMS0B
 generate-id($vlastView/preceding::tables) = IDACMS0B
(gID1 = gID2) = false

Cheers,
Dimitre Novatchev.





__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.