[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: banging my head against the wall (key, actually)
At 2015-04-24 01:30 +0000, Syd Bauman s.bauman@xxxxxxx wrote:
I fully expected method 1 and method 2 in the following stylesheet (which reads itself as input) to produce the same result. The problem is context. In your first loop, the item being examined is a string and so has no node context and so the current node context is used and so the key table is found in the tree of the input document since the current node is in the input document. In your second loop, the item being examined is a node in the tree created for the variable $set and so sets the context for the key table accordingly, but there are no <xd:p> elements in the tree of the context of the $set variable and so nothing is returned. When I use a third argument in your second loop in order to explicitly set the context to the input document, the values are returned as you would expect: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" exclude-result-prefixes="xs xd" version="2.0"> <xd:doc scope="stylesheet"> <xd:desc> <xd:p n="1">one</xd:p> <xd:p n="2">two dos</xd:p> <xd:p n="3">three tres III</xd:p> <xd:p n="4">f o u r</xd:p> </xd:desc> </xd:doc> <xsl:output method="text"/> <xsl:key name="tst" match="xd:desc/xd:p" use="."/> <xsl:variable name="home" select="/"/> <xsl:template match="/"> <xsl:variable name="set"> <xsl:apply-templates select="//xd:p"/> </xsl:variable> <!-- method 1: --> <xsl:for-each select="key('tst', $set/duck/string(.) )"> <xsl:message>debug1: <xsl:value-of select="@n"/></xsl:message> </xsl:for-each> <!-- method 2: --> <xsl:for-each select="$set/duck"> <xsl:message>debug2: <xsl:value-of select="key('tst', string(.), $home )/@n"/></xsl:message> </xsl:for-each> </xsl:template> <xsl:template match="xd:p"> <duck alpha="{substring('abcd',xs:integer(@n),1)}"><xsl:value-of select="."/></duck> </xsl:template> </xsl:stylesheet> T:\>xslt2 syd.xsl syd.xsl debug1: 1 debug1: 2 debug1: 3 debug1: 4 debug2: 1 debug2: 2 debug2: 3 debug2: 4 T:\> I hope this helps. . . . . . . . Ken
|
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
|