Subject: Re: [xsl] Merging XML from Lookup table From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sun, 22 Feb 2004 16:17:09 -0500 |
I have an XML in which data is coming from one source and another XML which contains the matching IDs and their format is completely different (I can modify the format if it doesn't work for the solution).
I need to generate an XML with matching IDs.
T:\ftemp2>type data.xml <data> <customer> <row num="2" zip="56780" typeID="1" /> <row num="3" zip="98264" typeID="1" /> <row num="5" zip="45424" typeID="2" /> <row num="1" zip="45722" typeID="1" /> <row num="4" zip="75565" typeID="2" /> </customer> </data>
T:\ftemp2>type table.xml <tables> <table name="customer"> <data> <row num="1" name="Kate Hudson" /> <row num="2" name="Jon Wright" /> <row num="3" name="Craig Wills" /> <row num="4" name="Ben Stills" /> <row num="5" name="Le Yan" /> <row num="6" name="Mc Kin" /> <row num="7" name="Vincent Dsouza" /> </data> </table> <table name="customer"> <data> <row typeID="1" type="Lease" /> <row typeID="2" type="Hire" /> </data> </table> </tables>
T:\ftemp2>type tracy.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="name-stuff" match="@name" use="../@num"/> <xsl:key name="type-stuff" match="@type" use="../@typeID"/>
<xsl:template match="row"> <xsl:variable name="num" select="@num"/> <xsl:variable name="typeID" select="@typeID"/> <row> <xsl:copy-of select="@zip"/> <xsl:for-each select="document('table.xml')"><!--change context--> <xsl:copy-of select="key('name-stuff',$num)"/> <xsl:copy-of select="key('type-stuff',$typeID)"/> </xsl:for-each> </row> </xsl:template>
<xsl:template match="@*|node()"><!--identity for all other nodes--> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <!--this cleans up the output--> <xsl:template match="text()[not(normalize-space())]"/>
T:\ftemp2>saxon data.xml tracy.xsl <?xml version="1.0" encoding="utf-8"?> <data> <customer> <row zip="56780" name="Jon Wright" type="Lease"/> <row zip="98264" name="Craig Wills" type="Lease"/> <row zip="45424" name="Le Yan" type="Hire"/> <row zip="45722" name="Kate Hudson" type="Lease"/> <row zip="75565" name="Ben Stills" type="Hire"/> </customer> </data> T:\ftemp2>
-- Public courses: Spring 2004 world tour of hands-on XSL instruction Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO United States: Washington, DC March 15; San Francisco, CA March 22 Finland April 26; Hong Kong May 17; Germany May 24; London June 07 World-wide on-site corporate, government & user group XML training
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) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Merging XML from Lookup table, Tracy | Thread | [xsl] split a string of expression , Ha Nguyen |
[xsl] split a string of expression , Ha Nguyen | Date | Re: David Carlisle =[xsl] no input , davidpbrown |
Month |