Subject: Re: [xsl] Selecting the value from diff i/p XML From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx> Date: Wed, 15 Sep 2010 23:51:04 +0200 |
<xsl:key name="idlist" match="data|item" use="@id"/> <xsl:variable name="data" select="document('Root1.xml')"/> <xsl:template match="/"> <xsl:for-each select="key( 'idlist', key('idlist', $data/root1/item/@id)/@id, $data ) "> <xsl:value-of select="@value"/> <br/> </xsl:for-each> </xsl:template>
<xsl:key name="idlist" match="item" use="@id"/> <xsl:variable name="data" select="document('Root2.xml')"/> <xsl:template match="/"> <xsl:for-each select="key('idlist', $data/root2/data/@id)"> <xsl:value-of select="@value"/> <br/> </xsl:for-each> </xsl:template>
Hello All,
I have two XML docs Root1.xml and Root2.xml
============================== Root1.xml looks like this <root1> <item id="1" value="A"/> <item id="21" value="B"/> <item id="3" value="C"/> <item id="45" value="D"/> <item id="5" value="E"/> <item id="6" value="F"/> <item id="78" value="G"/> <item id="8" value="H"/> <item id="9" value="I"/> <item id="10" value="J"/> </root1>
================================== Root2.XML looks like this
<root2> <data id="1"/> <data id="2"/> <data id="3"/> <data id="4"/> <data id="5"/> <data id="6"/> <data id="7"/> <data id="8"/> <data id="9"/> <data id="10"/> <data id="11"/> <data id="2"/> </root2> ===================================
I want the compare the @id of both the<item> and<data> and when it matches I want the value of the @value. so for in this case my output would be
A C E F H I J ======================================== I wrote this XSLT
<xsl:key name="idlist" match="root2/data" use="@id"/> <xsl:variable name="data" select="document('Root1.xml')"/> <xsl:template match="/"> <xsl:for-each select="key('idlist', $data/root1/item/@id)"> <xsl:value-of select="@id"/> <br/> </xsl:for-each> </xsl:template>
and I am getting this output
1 3 5 6 8 9 10 By applying this XSLT on Root2.xml I am able to print the @id of<data> element. But how to get the @value of<item> element from Root1.xml. I always want to apply my XSLT on Root2.xml
Thanks, Shashank jain
-- Gerrit Imsieke Geschdftsf|hrer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke@xxxxxxxxx, http://www.le-tex.de
Registergericht / Commercial Register: Amtsgericht Leipzig Registernummer / Registration Number: HRB 24930
Geschdftsf|hrer: Gerrit Imsieke, Svea Jelonek, Thomas Schmidt, Dr. Reinhard Vvckler ---------------------------------------------------------------------- Besuchen Sie uns auf der Frankfurter Buchmesse in Halle 4.2, Stand G446.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Selecting the value from diff, Shashank Jain | Thread | Re: [xsl] Selecting the value from , Imsieke, Gerrit, le- |
[xsl] Selecting the value from diff, Shashank Jain | Date | Re: [xsl] Selecting the value from , Imsieke, Gerrit, le- |
Month |