3

複数の xsl:templates を match="/" で異なる名前にすることはできますか? 基本的に、いくつかのレベルまで xml を反復し、条件が満たされた場合は "/" から再び反復を開始したいと考えています。そのため、オプション 1 とオプション 2 の両方がそれぞれandのようになるいくつかの条件に基づいて<xsl:call-template name="option-1">orを作成することを考えています。<xsl:call-template name="option-1"><xsl:template match="/" name="option-1"><xsl:template match="/" name="option-2">

より良い方法があれば、私はオープンです。私が望むのは、ルートノードから反復を再開することだけです。

4

1 に答える 1

4

あなたが探しているコンセプトはテンプレートモードです。定義できます

<xsl:template match="/" mode="option1">

同様option2に、モードのない最初の開始テンプレート

<xsl:template match="/">
  <xsl:choose>
    <xsl:when test="some-condition">
      <xsl:apply-templates select="/" mode="option1" />
    </xsl:when>
    <xsl:otherwise test="some-condition">
      <xsl:apply-templates select="/" mode="option2" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

XSLT 1.0 仕様XSLT 2.0 仕様

于 2012-12-11T14:45:46.803 に答える