XSLT external document lookup

jeanklann

New Member
I have a file.xml \[code\]<?xml version="1.0"?><Report> <row> <field1>test1</field1> <field2>test2</field2> <field3>test3</field3> </row> <row> <field1>test4</field1> <field2>test5</field2> <field3>test6</field3> </row></Report>\[/code\]And a lookup.xml\[code\]<?xml version="1.0"?><lookup> <field1>fieldA</field1> <field2>fieldB</field2> <field3>fieldC</field3></lookup>\[/code\]I am trying to get following output\[code\]<?xml version="1.0"?><Report> <row> <fieldA>test1</fieldA> <fieldB>test2</fieldB> <fieldC>test3</fieldC> </row> <row> <fieldA>test4</fieldA> <fieldB>test5</fieldB> <fieldC>test6</fieldC> </row></Report>\[/code\]So far I came up with following transform.xsl\[code\]<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:strip-space elements="*"/> <xsl:output indent="yes"/> <xsl:variable name="lookupDoc" select="document('lookup.xml')"/> <xsl:template match="Report"> <Items> <xsl:apply-templates/> </Items> </xsl:template> <xsl:template match="row"> <Item> <xsl:apply-templates/> </Item> </xsl:template> <xsl:template match="row/*"> <xsl:variable name="this" select="."/> <xsl:variable name="lookup"> <xsl:for-each select="$lookupDoc"> <xsl:key name="k1" match="local-name()" use="text()"/> <xsl:value-of select="key('k1', local-name($this))"/> </xsl:for-each> </xsl:variable> <fieldName name="{$lookup}"> <xsl:value-of select="."/> </fieldName> </xsl:template></xsl:stylesheet>\[/code\]New to Xsl hence mot sure why getting compiler error
 
Back
Top