[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Re: keys and data files

Subject: [xsl] Re: keys and data files
From: Richard Emberson <emberson@xxxxxxxxxxx>
Date: Sat, 28 Jul 2001 08:54:09 -0700

Actually, being new to xslt it was discovering that one could change the current
node to some imported document that was what surprised me that it actually worked.
What I did was:

input file:
<?xml version="1.0" encoding="UTF-8"?>
    <SomeOtherTag id="33322"/>
    <SomeOtherTag id="23492342"/>

testdata.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- file: testdata.xml -->
    <person id="33322">
    <person id="23492342">
    <person id="323423">

processing file:
<?xml version="1.0" encoding="UTF-8"?>

<xsl:key name="nv" match="people/person" use="@id"/>

<xsl:template match="SomeTag">
    <xsl:for-each select="child::SomeOtherTag">
        <xsl:variable name="id" select="@id"/>
        <xsl:for-each select="document('testdata.xml')">
            <xsl:variable name="node" select="key('nv', $id)"/>
Hi <xsl:value-of select="$node/name/first"/>,
Is "<xsl:value-of select="$node/email"/>" your email?

I was interested in a datastructure lookup capability. I originally had all the
data in a template using choose/when's for each type of data (first name, last
name, etc.) and yesterday morning I decided that there had to be a better
(object-oriented, group all the data together) way of doing it. Thus I came up
with the data structure lookup. (Of course I was not looking up first names, etc, but
rather xmlschema base and derived type information required for processing
xmlschema file converting the types to java classes).

I am cross posting to the xsl mailing list so that others can see the generality of
the "lookup table" technique; it can be used to lookup any static data as well as
markup instructions.


Dimitre Novatchev wrote:

> Richard,
> > I just joined the mailing list this morning. What was the "lookup" stylesheet?
> See:
> http://sources.redhat.com/ml/xsl-list/2001-06/msg01004.html
> and
> http://sources.redhat.com/ml/xsl-list/2001-06/msg01063.html
> The latter has a decent explanation "why this code works".


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

Current Thread