|
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"?>
<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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Re: keys and data files, Dimitre Novatchev | Thread | [xsl] saving in one if loop and usi, john smith |
| Re: [xsl] Installing Sablotron & Ex, dante | Date | [xsl] servlet returns well-formed X, Robert Koberg |
| Month |