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

Re: Antw: Merging two xml files

Subject: Re: Antw: Merging two xml files
From: "Agnes Kielen" <agnes.kielen@xxxxxxx>
Date: Tue, 13 Jan 2004 18:30:25 +0100
two xml xsl
Hi,
You can better send questions to the xsl-list. In this way everybody can
learn from the questions and answers and everyone can answer!

Change (untested):
<xsl:variable name="pin" select="$emps//employee[@id = $id]/@pincode"/>
<employee>
     <xsl:if test="$pin>
          <xsl:attribute name="pincode">
               <xsl:value-of select="$pin"/>
          </xsl:attribute>
     </xsl:if>
     <!-- copy the child nodes -->
          <xsl:copy-of select="*"/>
         <!-- copy the address -->
         <xsl:copy-of select="$emps//employee[@id =$id]/address"/>
  </employee>

Variable $pin will test to true if it exists otherwise it will be false.

Cheers,
Agnes



----- Original Message ----- 
From: "Arulraj" <p_arulraj@xxxxxxxxx>
To: <agnes.kielen@xxxxxxx>
Sent: Tuesday, January 13, 2004 11:08 AM
Subject: Re: Antw:  Merging two xml files


> Hi Agnes,
>  This works fine. I have one more doubt. If I have
> pincode attribute in second.xml, then In Ouput should
> have <employee pincode=""> otherwise I no need to have
> pincode attribute just <employee> is enough.
>
> So I need to check pincode is appear in second XML
> then adding it to resultant <employee> element.
>
> If you got an idea!
> Please reply me.
>
> Thanking you,
> Arul
>
> --- agnes.kielen@xxxxxxx wrote:
> > Hi Arul,
> >
> > <?xml version="1.0"?>
> > <xsl:stylesheet
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > version="1.0">
> >   <xsl:output method="xml" indent="yes"/>
> >   <!-- load the merge file -->
> >   <xsl:variable name="emps"
> > select="document('employeeAddresses.xml')"/>
> >   <xsl:template match="/">
> >      <employees>
> > <xsl:for-each select="employees/employee"> <!--
> > cache the employee's ID --> <xsl:variable
> > name="id" select="@id"/> <!-- copy the pincode of
> > the second XML --> <employee
> > pincode="{$emps//employee[@id = $id]/@pincode}">
> >         <!-- copy the child nodes -->
> >         <xsl:copy-of select="*"/>
> > <!-- copy the address -->
> >         <xsl:copy-of select="$emps//employee[@id =
> > $id]/address"/>
> >     </employee>
> >    </xsl:for-each>
> > </employees>
> > </xsl:template>
> > </xsl:stylesheet>
> >
> > I changed the
> > <xsl:variable name="id"><xsl:value-of
> > select="@id"/></xsl:variable>
> > in <xsl:variable name="id" select="@id"/>
> > This is shorter to write, easier to read and you
> > don't create a RTF.
> > Furhtermore I changed child::* in *.
> >
> > I select the correct nodes from employeeAddress.xml
> > with the help of the following pattern:
> > $emps//employee[@id = $id].
> > In english this means something like select those
> > employee from the second file from which the
> > id-attribute is equal to the current id in the main
> > xml.
> >
> >
> > Cheers,
> > Agnes
> >
> >
> >
> >
> >
> >
> >
> >  XSL-List info and archive:
> > http://www.mulberrytech.com/xsl/xsl-list
> >
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
> http://hotjobs.sweepstakes.yahoo.com/signingbonus
>



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.