[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Having trouble with key() function and the top parameter


Subject: Re: [xsl] Having trouble with key() function and the top parameter
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 6 Dec 2015 00:53:56 -0000

> Why does this not work the way I want it to?

Because you are using a buggy (non-compliant) XSLT 2.0 processor.

With Saxon 9.6J I get the correct output.

Cheers,
Dimitre

On Sat, Dec 5, 2015 at 3:34 PM, Marvin NotMyRealNameDuh
marvin.the.paranoid@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
wrote:

> 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
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <-list/782854> (by
> email <>)
>



-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.


Current Thread
Keywords