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

Re: keys and data files

Subject: Re: keys and data files
From: Richard Emberson <emberson@xxxxxxxxxxx>
Date: Sat, 28 Jul 2001 08:54:09 -0700
 Re: keys and data files
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"?>
<SomeTag>
    <SomeOtherTag id="33322"/>
    <SomeOtherTag id="23492342"/>
</SomeTag>

testdata.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- file: testdata.xml -->
<people>
    <person id="33322">
        <name>
            <first>tom</first>
            <last>jones</last>
        </name>
        <email>tjones@xxxxxxxxx</email>
    </person>
    <person id="23492342">
        <name>
            <first>john</first>
            <last>donne</last>
        </name>
        <email>jdonne@xxxxxxxxxxxx</email>
    </person>
    <person id="323423">
        <name>
            <first>frank</first>
            <last>wright</last>
        </name>
        <email>fwright@xxxxxxxxxxxxxxxxxxx</email>
    </person>
</people>

processing file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xalan="http://xml.apache.org/xslt"
        >

<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)"/>
<OUT>
Hi <xsl:value-of select="$node/name/first"/>,
Is "<xsl:value-of select="$node/email"/>" your email?
</OUT>
        </xsl:for-each>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

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.

Richard



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

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.