0
    <xsl:template name="split">
    <xsl:param name="list"/>
        <xsl:variable name="first">
                         <xsl:value-of select="substring-before($list,' ')"/>
                    </xsl:variable>
        <xsl:copy-of select="$first"/>
</xsl:template>

           <xsl:variable name="test">c0 c1 c2 c3 c4</xsl:variable>
                <xsl:variable name="var2>
                  <xsl:call-template name="split">
                        <xsl:with-param name="returnvalue">
                             <xsl:value-of select="$test"></xsl:with-param>
                  </xsl:call-template>
              </xsl:variable>

// processing done

i want to return value from template as c0 then back to template match do processing then again go to split template again return c1 done same processing then back to split template then again processing in match template; depending upon the value of test variable...

How could i retreive these values one by one and process the code..??

4

1 回答 1

0

此样式表将向前扫描您的输入字符串:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:output method="text"/>

    <xsl:variable name="string" select="'c0 c1 c2 c3 c4'"/>
    <xsl:variable name="delim" select="' '"/>

    <xsl:template match="/">
        <xsl:call-template name="wrapper">
            <xsl:with-param name="string" select="$string"/>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="wrapper">
        <xsl:param name="string"/>
        <xsl:choose>
            <!-- handle empty input -->
            <xsl:when test=" $string = '' "/>

            <!-- handle next token -->
            <xsl:when test="contains($string, $delim)">
                <xsl:call-template name="process">
                    <xsl:with-param name="substring" select="substring-before($string,$delim)"/>
                </xsl:call-template>
                <xsl:call-template name="wrapper">
                    <xsl:with-param name="string" select="substring-after($string,$delim)"/>
                </xsl:call-template>
            </xsl:when>

            <!-- handle last token -->
            <xsl:otherwise>
                <xsl:call-template name="process">
                    <xsl:with-param name="substring" select="$string"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="process">
        <xsl:param name="substring"/>
        <xsl:text>RECEIVED SUBSTRING: </xsl:text>
        <xsl:value-of select="$substring"/>
        <xsl:text>&#x000A;</xsl:text>
    </xsl:template>

</xsl:stylesheet>

产生以下输出:

RECEIVED SUBSTRING: c0
RECEIVED SUBSTRING: c1
RECEIVED SUBSTRING: c2
RECEIVED SUBSTRING: c3
RECEIVED SUBSTRING: c4
于 2013-04-11T16:17:10.277 回答