0

我有一个 xsl 参数,它是一个字符串。我想解析该字符串,将其拆分,并且对于每个子字符串值,我想在 xsl 中应用模板。

这可能吗?如果是这样,您能否提出一个乐观的解决方案?

谢谢

4

2 回答 2

1

不确定您的意思,但复制此模式可能会有所帮助:XSLT - 将逗号分隔的文本拆分和呈现为 HTML 的最佳方式

于 2010-07-20T05:21:57.180 回答
1

编辑:误解了这个问题,对不起。

答案是肯定的。

输入:

<secuence>Item1 Item2 Item3</secuence>

样式表:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="secuence/text()" name="secuence">
        <xsl:param name="string" select="."/>
        <xsl:param name="separator" select="' '"/>
        <xsl:if test="$string != ''">
            <xsl:choose>
                <xsl:when test="contains($string,$separator)">
                    <xsl:call-template name="secuence">
                        <xsl:with-param name="string" select="substring-before($string,$separator)"/>
                        <xsl:with-param name="separator" select="$separator"/>
                    </xsl:call-template>
                    <xsl:call-template name="secuence">
                        <xsl:with-param name="string" select="substring-after($string,$separator)"/>
                        <xsl:with-param name="separator" select="$separator"/>
                    </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                    <!-- Your desired template -->
                    <Item>
                        <xsl:value-of select="$string"/>
                    </Item>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

结果:

<secuence>
    <Item>Item1</Item>
    <Item>Item2</Item>
    <Item>Item3</Item>
</secuence>
于 2010-07-20T14:55:48.873 回答