xsl-list
[Top] [All Lists]

Re: [xsl] Can templates be invoked based on the value of a variable?

2009-04-01 16:23:15
pilgrim cnonline.net schrieb am 01.04.2009 um 14:52:01 (-0500):
I would like to be able to invoke templates based on the value of a
variable.

My data has the structure:

<data>
    <item1>
        ...
    </item1>
    <item2>
        ....
    </item2>
</data>

I want to process the nodes <item1/> or <item2/>, but not both,
depending on a variable derived from some other processing.

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

  <xsl:template match="data">
    <xsl:variable name="i" select="2"/>
    <xsl:variable name="item" select="concat( 'item', $i)"/>
    <xsl:apply-templates select="*[ local-name() = $item ]"/>
  </xsl:template>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

But I think there is nothing wrong with using <xsl:choose> here.

Michael Ludwig

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