2013-04-10 55 views
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> 

//处理完成

我想从模板返回值C0再回到模板匹配做处理,然后再去分割模板再次返回c1完成相同的处理,然后返回到分割模板,然后再次在匹配模板中处理Ë;取决于测试变量的值...

我怎样才能逐个检索这些值并处理代码?

回答

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 
+0

感谢你的帮助,但我想首先我取C0然后处理一些代码然后c1处理相同的代码等等。 – 2013-04-13 08:23:27

+0

你应该能够用更有用的东西来替换'',它可以处理你的每个项目,但是我不清楚你的其他需求。 – 2013-04-13 22:44:38