[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: HOWTO : Lookup tables
Benoit Aumars wrote: > > I'm looking for a sample code to transform one xml file into another one > using a 'lookup tables' xml file. > Suppose I have this before.xml : > > <?xml version="1.0"?> > <in> > <A code1="01" code2="Hello" /> > <A code1="02" code2="world" /> > </in> > > and I want to transform it into after.xml : > <?xml version="1.0"?> > <in> > <Label1>01</Label1> > <Label2>Hello</Label2> > <Label1>02</Label1> > <Label2>world</Label2> > </in> > using this 'lookup tables' xml file ( something like this / similar to this > ) : > <?xml version="1.0"?> > <lookup> > <abbr>code1</abbr><name>Label1</name> > <abbr>code2</abbr><name>Label2</name> > </lookup> > > Can someone help me out please ? The following stylesheet produces your desired output when applied on your xml source: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" omit-xml-declaration="yes"/> <xsl:key name="kLookup" match="name" use="preceding-sibling::abbr[1]"/> <xsl:template match="/"> <in> <xsl:apply-templates select="in/A/@*"/> </in> </xsl:template> <xsl:template match="A/@*"> <xsl:variable name="input" select="."/> <xsl:for-each select="document('lookup.xml')"> <xsl:for-each select="key('kLookup', name($input))"> <xsl:element name="{.}"> <xsl:value-of select="$input"/> </xsl:element> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:stylesheet> Cheers, Dimitre Novatchev. __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/ 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
|