0

文字列の xsl パラメータがあります。その文字列を解析して分割し、部分文字列の値ごとに xsl にテンプレートを適用したいと考えています。

これは可能ですか?もしそうなら、楽観的な解決策をアドバイスしてもらえますか?

ありがとう

4

2 に答える 2

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 に答える
1

意味がわかりませんが、このパターンをコピーすると役立つ場合があります: XSLT - カンマ区切りのテキストを HTML として分割してレンダリングする最良の方法

于 2010-07-20T05:21:57.180 に答える