My XML before applying xslt looks like this:
<vehicle>
<driver repeatingtype="list">
<data repeatingindex="1">
<name>driver1</name>
<age>25</age>
</data>
<data repeatingindex="2">
<name>def</name>
<age>25</age>
</data>
<data repeatingindex="3">
<name>ghi</name>
<age>25</age>
</data>
</driver>
</vehicle>
I want to write an xslt which which gives me the xml in the following format -
<vehicle>
<maindriver> [Comment: This always has the first element(1) in the driver list]
<name>driver1</name>
<age>25</age>
</maindriver>
<additionaldrivers>
<name>def</name>
<age>25</age>
<name>ghi</name>
<age>25</age>
</additionaldrives>
</vehicle>
How do i write the xslt to pick up the first element in the page list and put it in the main driver tag and the rest of the elements in the additional driver tag. I am looking for something which does not repeat the code for the template. I have written the following xslt but has duplicate code for the driver tag -
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="vehicle">
<maindriver>
<xsl:apply-templates select="driver/data[1]"/>
</maindriver>
<additionaldrivers>
<xsl:apply-templates select="driver"/>
</additionaldrivers>
</xsl:template>
<xsl:template match="driver/data[1]">
-----Code to capture the details----
</xsl:template>
<xsl:template match="driver">
<xsl:choose>
<xsl:when test="'$data -gt 1'">
<xsl:for-each select="rowdata">
---- Repeating Code as of the main driver----
</xsl:for-each>
</xsl:when>
</xsl:choose>
</xsl:template>