Subject: Antw: [xsl] Merging two xml files From: agnes.kielen@xxxxxxx Date: Tue, 13 Jan 2004 10:15:18 +0100 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Merging two xml files, Kielen, Agnes | Thread | Re: Antw: [xsl] Merging two xml fil, Agnes Kielen |
RE: [xsl] Merging two xml files usi, Bhaskar Reddy | Date | RE: [xsl] Sorting different date fo, Josh Canfield |
Month |