XSL模板可以匹配*ALL*模式吗?

Dir*_*mar 14 xslt

有没有办法编写一个在所有模式下匹配的XSL 1.0模板?

或者我是否必须为每个现有模式编写单独的模板(包括将来添加的模式的其他模板)?

这是我有的:

<xsl:apply-templates mode="mode1" />
    ...
<xsl:apply-templates mode="mode2" />
    ...
<!-- Do not process text content of nodes no matter in what mode -->
<!-- Is there a way to have only one template here? -->
<xsl:template match="text()" mode="mode1" />
<xsl:template match="text()" mode="mode2" />
Run Code Online (Sandbox Code Playgroud)

ann*_*ata 7

预定义模式:( #all仅适用于XSLT 2.0).

编辑:使用1.0复制共享模式行为

<xsl:template match="/">
    <xsl:variable name="choice" select="'a'"/><!-- input seed here -->
    <xsl:choose>
        <xsl:when test="$choice='a'">
            <xsl:apply-templates mode="a"/>
        </xsl:when>
        <xsl:when test="$choice='b'">
            <xsl:apply-templates mode="b"/>
        </xsl:when>
    </xsl:choose>
</xsl:template>

<xsl:template match="*" mode="a">
    [A]
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="*" mode="b">
    [B]
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="text()">
    [ALL]
</xsl:template>
Run Code Online (Sandbox Code Playgroud)