Subject: [xsl] keys and data files From: Richard Emberson <emberson@xxxxxxxxxxx> Date: Fri, 27 Jul 2001 12:44:53 -0700 |
I have an input xml to be processed, a xsl file with will be used to transform the input file, and a xml data file that hold records that map from one string to another: input file: <?xml version="1.0" encoding="UTF-8"?> <foo> <bar n="one"/> <bar n="three"/> <bar n="four"/> </foo> xsl file: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet ....> <xsl:key name="nv" match="test:X/test:nv" use="@name"/> <xsl:template match="foo"> <xsl:for-each select="child::bar"> <xsl:variable name="name" select="@n"/> <xsl:for-each select="document('data.xml')"> <xsl:variable name="node" select="key('nv', $name)"/> <OUT2 name="{$name}" value="{$node/@value}"/> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:stylesheet> data file: <?xml version="1.0" encoding="UTF-8"?> <test:X xmlns:test="http://foo.bar" > <test:nv name="one" value="1"/> <test:nv name="two" value="2"/> <test:nv name="three" value="3"/> <test:nv name="four" value="4"/> </test:X> Now this actually works, the output is: <OUT2 value="1" name="one"/><OUT2 value="3" name="three"/><OUT2 value="4" name="four"/> My question is I was under the (mis) impression that a key was generated where it was declared, not where it is used. But this is clearly wrong in this case since the document applied to the key is specified after it is declared (infact the document name, in this case 'data.xml', could actually have been dynamically generated). So, how efficient is a key, especially in this case. Is it implementation dependent; associated with each document is zero or more keys which (being basically a static hashtable) is generated the first time it is needed and after that is simply re-used? BTW I am amazed that the above xsl code works; xsl is truly a freaky language. RME XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] keys and performance, Clapham, Paul | Thread | [xsl] Re: RE: Selecting a node set, Dimitre Novatchev |
[xsl] Text output and whitespace, Larry Garfield | Date | [xsl] Re: keys and data files, Dimitre Novatchev |
Month |