|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Having trouble with key() function and the top paramet
Hi,
Here is my testcase:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="xml" indent="yes" />
<xsl:key name="lookup" match="table" use="@object-id" />
<xsl:template match="/">
<xsl:variable name="old">
<model>
<schema name="ow_ent">
<table name="x" object-id="a" />
<table name="z" object-id="b" />
</schema>
<schema name="ow_lnk">
<table name="y" object-id="a" />
</schema>
</model>
</xsl:variable>
<xsl:for-each select="$old/model/schema[@name = 'ow_ent']/table">
<xsl:variable name="table-id" select="@object-id" />
<xsl:for-each select="key('lookup', $table-id,
$old/model/schema[@name = 'ow_ent'])">
<xsl:message>Found table <xsl:value-of select="@name"
/></xsl:message>
</xsl:for-each>
<xsl:message>---------- The way it should work
-----------</xsl:message>
<xsl:for-each select="key('lookup',
$table-id)[ancestor::schema/@name = 'ow_ent']">
<xsl:message>Found actual table <xsl:value-of
select="@name" /></xsl:message>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The usage of key() above the "The way it should work" message uses the
"top" argument to the function. The XSL spec says that the nodes returned
by the key() function will be the nodes selected by the first two arguments
of key() such that their ancestors intersect with the "top" argument. So,
key('lookup', 'a') in the context of /model/schema[@name = 'ow_ent'] should
only find /model/schema[@name = 'ow_ent']/table[@name = x] . Instead it is
finding /model/schema[@name = 'ow_lnk']/table[@name = 'y'] as well.
Why does this not work the way I want it to?
Thanks,
Marvin the Paranoid
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








