xml - Merging data from two files into one using XSL -
i have 2 xml files trying merge elements using xsl.
xml1:
<all xmlns:a="http://example.com/ns1" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <a:businessunit> <a:businessunitcode>sgs</a:businessunitcode> <a:longname>singapore global sourcing</a:longname> <a:parentbusinessunitcode>cgs</a:parentbusinessunitcode> </a:businessunit> <a:businessunit> <a:businessunitcode>egh</a:businessunitcode> <a:longname>ems global hq</a:longname> <a:parentbusinessunitcode xsi:nil="true"/> </a:businessunit>
xml2:
<get_productfamily xmlns:aa="http://example.com/ns2"> <aa:productfamily> <aa:integrationid>2323</aa:integrationid> <aa:parentbusinessunitcode>egh</aa:parentbusinessunitcode> </aa:productfamily> <aa:productfamily> <aa:integrationid>3434</aa:integrationid> <aa:parentbusinessunitcode>cgs</aa:parentbusinessunitcode> </aa:productfamily> <aa:productfamily> <aa:integrationid>4545</aa:integrationid> <aa:parentbusinessunitcode>cdd</aa:parentbusinessunitcode> </aa:productfamily> </get_productfamily>
output:
<grouplist> <group> <name>egh - ems global hq</name> <productlinelist> <productline> <name>egh</name> <code>2323</code> </productline> </productlinelist> </group> <grouplist>
i want read business unit info 1st file , product family info 2nd file , generate grouping info.
steps are: read business unit
group name concatenation of a:businessunitcode , a:longname (i did part)
when a:parentbusinessunitcode blank, read a:businessunitcode, search businessunitcode in 2nd file.
if a:businessunitcode(1st file) equal aa:parentbusinessunitcode (2nd file) print integration id.
please help me new xsl.
i searched bussinessunitcode in sec xml , displayed corresponding data. notice used document() function read sec xml.
<xsl:template match="/"> <grouplist> <group> <xsl:apply-templates/> </group> </grouplist> </xsl:template> <xsl:template match="a:businessunit"> <xsl:variable name="businesscode" select="a:businessunitcode"/> <name> <xsl:value-of select="$businesscode"/> - <xsl:value-of select="a:longname"/> </name> <xsl:if test="a:parentbusinessunitcode[@i:nil='true']"> <productlinelist> <xsl:for-each select= "document('xml2.xml')/get_productfamily/aa:productfamily"> <xsl:if test="aa:parentbusinessunitcode = $businesscode"> <productline> <name><xsl:value-of select="$businesscode"/></name> <code><xsl:value-of select="aa:integrationid"/></code> </productline></xsl:if> </xsl:for-each> </productlinelist> </xsl:if> </xsl:template> </xsl:stylesheet>
xml xslt xslt-1.0 merging-data
No comments:
Post a Comment