xsl-list
[Top] [All Lists]

Re: [xsl] key( 'myKey', 'key', $current) searches only the sub tree from $current

2008-02-23 09:16:27
"Johannes" == Johannes Neubauer 
<johannes(_dot_)neubauer(_at_)cs(_dot_)tu-dortmund(_dot_)de> writes:

    Johannes> Hi, I have a <xsl:key> that maps unique attribute values
    Johannes> of sibling-elements to the respective element. When I
    Johannes> use the key() function in a <xsl:function> I have to
    Johannes> submit a node as a third argument, so that it's clear
    Johannes> which source document is used (there's no context node
    Johannes> in functions available).

    Johannes> So I tried this:

    Johannes> xsl:key: <xsl:key match="book" name="myKey" use="@id"/>

    Johannes> function call in XPath: key('myKey', '100', $current) (:
    Johannes> $current is the context node supplied as a parameter to
    Johannes> the xsl:function :)

    Johannes> source doc: <test> ~ <book id="100"/> ~ <book id="101"/>
    Johannes> ~ <book id="102"/> ~ <book id="103"/> </test>

    Johannes> But I find the respective book element only if it is
    Johannes> $current. When I change the function call to this:
    Johannes> key('myKey', '100', root($current))

    Johannes> I find it independent from which element $current is, it
    Johannes> has to be from the right source document only.

    Johannes> "XSLT 2.0 3rd edition" from Michael Kay page 574 says,
    Johannes> that the supplied ~ third argument must not be the
    Johannes> document node, but any node of the source document.

    Johannes> Is this a bug in Saxon or one of the things that changed
    Johannes> in the spec after publishing the book? I didn't find the
    Johannes> part in the online documentation, where the xslt
    Johannes> functions are described.

It's 16.3.2.

"The third argument is used to identify the selected subtree. If the
argument is present, the selected subtree is the set of nodes that
have $top as an ancestor-or-self node. If the argument is omitted, the
selected subtree is the document containing the context node. This
means that the third argument effectively defaults to /." 

which is not what you described. If Michael's 3rd edition (I only have
the 2nd edition - from years back) says what
you described, then best buy the fourth edition when it comes out.
-- 
Colin Adams
Preston Lancashire

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>