xsl-list
[Top] [All Lists]

Re: [xsl] xml to xml mapping - how to combine two groups

2008-01-08 08:33:16

<x>
<LIST_GROUP_A>
<GROUP_A>
<COLOR>red</COLOR>
</GROUP_A>
</LIST_GROUP_A>
<LIST_GROUP_B>
<GROUP_B>
<SHAPE>round</SHAPE>
</GROUP_B>
<GROUP_B>
<SHAPE>square</SHAPE>
</GROUP_B>
</LIST_GROUP_B>
</x>



<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="x">
 <LIST_COMBINED>
   <xsl:variable name="a" select="LIST_GROUP_A/*"/>
   <xsl:variable name="b" select="LIST_GROUP_B/*"/>
   <xsl:for-each select="$a|$b[position()&gt;count($a)]">
     <xsl:variable name="p" select="position()"/>
   <COMBINED>
     <xsl:copy-of select="$a[$p]/*|$b[$p]/*"/>
   </COMBINED>
   </xsl:for-each>
 </LIST_COMBINED>
</xsl:template>

</xsl:stylesheet>



$ saxon map.xml map.xsl
<?xml version="1.0" encoding="utf-8"?>
<LIST_COMBINED>
   <COMBINED>
      <COLOR>red</COLOR>
      <SHAPE>round</SHAPE>
   </COMBINED>
   <COMBINED>
      <SHAPE>square</SHAPE>
   </COMBINED>
</LIST_COMBINED>




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--