xsl-list
[Top] [All Lists]

Re: [xsl] Adding child element based on attribute value [XSLT 1.0]

2011-01-08 06:57:20
pankaj(_dot_)c(_at_)thomsondigital(_dot_)com wrote:
AHA!!!! Thanks Ken but I am using 1.0.

Write a named template with a param that is increased on each recursive call:

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

  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="my_group">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:call-template name="make-group">
        <xsl:with-param name="i" select="1"/>
        <xsl:with-param name="l" select="3"/>
      </xsl:call-template>
    </xsl:copy>
  </xsl:template>

  <xsl:template name="make-group">
    <xsl:param name="i"/>
    <xsl:param name="l"/>
    <xsl:if test="$i &lt;= $l">
      <group name="type{$i}"/>
      <xsl:call-template name="make-group">
        <xsl:with-param name="i" select="$i + 1"/>
        <xsl:with-param name="l" select="$l"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>


--

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
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>
--~--