|
[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
At 2004-01-06 02:55 -0500, Scott Anguish wrote:
Your one XSLT stylesheet can match nodes from different documents just by saying: But you missed what I said later in my message you quoted about setting the context for use of the key function. Note that the processor typically caches documents opened using the document() function so you can repeatedly call it without a performance penalty. Below is a one-pass solution to your problem ... I hope this time it helps. ................... Ken p.s. for those interested in US east coast XSL training, we still don't have enough preregistered students for a decision tomorrow to go with the course or cancel it and save the venue deposit fees ... if you have been thinking about registering, please do so today or the course might not happen next month. Thanks! T:\ftemp>type thedocument.xml <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> 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:output indent="yes"/> <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></xsl:stylesheet> T:\ftemp>saxon -o scott.out scott.xml scott.xsl 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!
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 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








