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 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Seek a simple XPath 2.0 e, Michael Kay mike@xxx | Thread | Re: [xsl] Having trouble with key(), Dimitre Novatchev dn |
Re: [xsl] Seek a simple XPath 2.0 e, Michael Kay mike@xxx | Date | Re: [xsl] Having trouble with key(), Dimitre Novatchev dn |
Month |