[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

keys and data files

Subject: keys and data files
From: Richard Emberson <emberson@xxxxxxxxxxx>
Date: Fri, 27 Jul 2001 12:44:53 -0700
key name data file
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.