This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Re: limiting preceding axis by ancestor
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 8 May 2002 00:46:16 -0700 (PDT)
- Subject: [xsl] Re: Re: limiting preceding axis by ancestor
- Reply-to: xsl-list at lists dot mulberrytech dot com
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
, '
 '
)"/>
<xsl:value-of
select="concat('generate-id($vlastView/preceding::tables) = '
, $vID2
, '
'
)"/>
<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