[xsl] keys and data files

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

input file:

<?xml version="1.0" encoding="UTF-8"?>
    <bar n="one"/>
    <bar n="three"/>
    <bar n="four"/>

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}"/>


data file:

<?xml version="1.0" encoding="UTF-8"?>
    <test:nv name="one" value="1"/>
    <test:nv name="two" value="2"/>
    <test:nv name="three" value="3"/>
    <test:nv name="four" value="4"/>

Now this actually works, the output is:

<OUT2 value="1" name="one"/><OUT2 value="3" name="three"/><OUT2 value="4"

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
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


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread