Input xml is like as,
<figure id="c035_f001" counter="yes">
<legend><para>The TLIF is indicated to aid reduction of spondylolisthesis and restore disc height, which decompresses the foramina.</para></legend>
<subfigure>
<graphic position="center" fileref="images/9781626230408_c035_f001.jpg"/>
</subfigure>
<subfigure>
<graphic position="center" fileref="images/9781626230408_c035_f001a.jpg"/>
</subfigure>
</figure>
Output should be,
<figure counter="yes">
<legend><para>The TLIF is indicated to aid reduction of spondylolisthesis and restore disc height, which decompresses the foramina.</para></legend>
<subfigure id="c035_f001">
<graphic position="center" fileref="images/9781626230408_c035_f001.jpg"/>
</subfigure>
<subfigure>
<graphic position="center" fileref="images/9781626230408_c035_f001a.jpg"/>
</subfigure>
</figure>
We wrote XSLT like as shown below.
<xsl:template match="subfigure">
<xsl:variable name="fig" select="parent::figure/@id"></xsl:variable>
<xsl:choose>
<xsl:when test="subfigure[not[@id]]">
<xsl:if test="subfigure[not[@id]]">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="id">
<xsl:value-of select="$fig"></xsl:value-of>
</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
While using above xslt, we are getting output as,
<figure counter="yes">
<legend><para>The TLIF is indicated to aid reduction of spondylolisthesis and restore disc height, which decompresses the foramina.</para></legend>
<subfigure id="c035_f001">
<graphic position="center" fileref="images/9781626230408_c035_f001.jpg"/>
</subfigure>
<subfigure id="c035_f001">
<graphic position="center" fileref="images/9781626230408_c035_f001a.jpg"/>
</subfigure>
</figure>
The "id" repeating on both the "subfigure" elements. But we require only on first position. Could you please guide us.