[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Selecting the value from diff i/p XML

Subject: Selecting the value from diff i/p XML
From: Shashank Jain <shashankjain@xxxxxxxx>
Date: Wed, 15 Sep 2010 16:21:50 -0500
 Selecting the value from diff i/p XML
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.