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

Re: Looking up keys in a separate xml file

Subject: Re: Looking up keys in a separate xml file
From: Scott Anguish <sanguish@xxxxxxxxxxx>
Date: Tue, 6 Jan 2004 02:55:28 -0500
scott anguish
Your one XSLT stylesheet can match nodes from different documents just by saying:

<xsl:template match="descriptions">......

Where elsewhere in your document you do the push:

<xsl:apply-templates select="document('thedocument.xml')/descriptions"/>

If you have a <descriptions> element in both input files, then you could either use modes or you could qualify an ancestral element that is unique in each file.



I tried that a number of different ways, but still had to fall back to the multiple pass methods... So I'm clearly not understanding...


I have a description file

<Descriptions>
<Description name="a"><Para>Description for <subname />With Lookup Name A</Para></Description>
<Description name="b"><Para>Description for <subname />With Lookup Name B</Para></Description>
<Description name="c"><Para>Description for <subname />With Lookup Name C</Para></Description>
</Descriptions>


and I have my file that I need to insert those elements into

<Items>
<Item><Name>Item A</Name><InsertDescription lookup="a" /></Item>
<Item><Name>Item B</Name><InsertDescription lookup="b" /></Item>
<Item><Name>Item C</Name><InsertDescription lookup="a" /></Item>
<Item><Name>Item D</Name><InsertDescription lookup="c" /></Item>
<Item><Name>Item E</Name><InsertDescription lookup="a" /></Item>
</Items>


Each InsertDescription needs to lookup the corresponding Description/@name and insert the full contents (so, for a lookup="a", I get '<Description name="a"><Para>Description for <subname />With Lookup Name A</Para></Description>')


So, it sounds like I'd do this

<?xml version='1.0' encoding='iso-8859-1'?>

<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method='xml' version='1.0' encoding='iso-8859-1' omit-xml-declaration="yes" indent="yes"/>


<xsl:key name="descriptionlookup" match="Descriptions/Description" use="@name"/>

<xsl:template match="/">
<xsl:apply-templates select="document('descriptions.xml')/descriptions"/>
<xsl:apply-templates />
</xsl:template>


<xsl:template match="InsertDescription">
   <xsl:value-of select="key('descriptionlookup',@lookup)"/>
    <xsl:value-of select="@lookup" />
</xsl:template>

</xsl:stylesheet>


but I'm not getting any results aside from the Item name's being output...



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.