Subject: Re: [xsl] Looking up keys in a separate xml file From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 06 Jan 2004 09:44:55 -0500 |
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...
T:\ftemp>type scott.xml <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>
T:\ftemp>type scott.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="descriptionlookup" match="Descriptions/Description" use="@name"/>
<xsl:template match="Items|Item|Name"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
<xsl:template match="InsertDescription"> <xsl:variable name="lookup" select="@lookup"/> <xsl:for-each select="document('thedocument.xml')"> <xsl:copy-of select="key('descriptionlookup',$lookup)"/> </xsl:for-each> </xsl:template>
T:\ftemp>type scott.out <?xml version="1.0" encoding="utf-8"?> <Items>
<Item> <Name>Item A</Name> <Description name="a"> <Para>Description for <subname/>With Lookup Name A</Para> </Description> </Item>
<Item> <Name>Item B</Name> <Description name="b"> <Para>Description for <subname/>With Lookup Name B</Para> </Description> </Item>
<Item> <Name>Item C</Name> <Description name="a"> <Para>Description for <subname/>With Lookup Name A</Para> </Description> </Item>
<Item> <Name>Item D</Name> <Description name="c"> <Para>Description for <subname/>With Lookup Name C</Para> </Description> </Item>
<Item> <Name>Item E</Name> <Description name="a"> <Para>Description for <subname/>With Lookup Name A</Para> </Description> </Item>
</Items> T:\ftemp>rem Done!
-- North America (Washington, DC): 3-day XSLT/2-day XSL-FO 2004-02-09 Instructor-led on-site corporate, government & user group training for XSLT and XSL-FO world-wide: please contact us for the details
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) ISBN 0-13-065196-6 Definitive XSLT and XPath ISBN 0-13-140374-5 Definitive XSL-FO ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath ISBN 1-894049-11-X Practical Formatting Using XSL-FO Member of the XML Guild of Practitioners: http://XMLGuild.info Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Looking up keys in a sepa, Scott Anguish | Thread | Re: [xsl] Looking up keys in a sepa, Anthony Zawacki |
RE: [xsl] Looking for shorthand for, Michael Kay | Date | Re: [xsl] Looking up keys in a sepa, David Carlisle |
Month |