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

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

Subject: [xsl] Having trouble with key() function and the top parameter
From: "Marvin NotMyRealNameDuh marvin.the.paranoid@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 5 Dec 2015 23:33:56 -0000


    Here is my testcase:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    <xsl:output method="xml" indent="yes" />

    <xsl:key name="lookup" match="table" use="@object-id" />

    <xsl:template match="/">
        <xsl:variable name="old">
                <schema name="ow_ent">
                    <table name="x" object-id="a" />
                    <table name="z" object-id="b" />
                <schema name="ow_lnk">
                    <table name="y" object-id="a" />

        <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>----------  The way it should work
            <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>




    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?

Marvin the Paranoid

Current Thread