XST - use the output from the call template as the return value

Suppose I have a template foothat can output something specified by a parameter. Now I want to use this output as a parameter for my other template loop, so that I can cyclically output the output a certain number of times. I tried something along the way

    <xsl:call-template name="loop">
        <xsl:with-param name="times" select="someParam"/>
        <xsl:with-param name="output">
            <xsl:call-template name="foo">
                <xsl:with-param name="type" select="something"/>
            </xsl:call-template>
        </xsl:with-param>
    </xsl:call-template>

In other words, outputit should now contain the output of the call foo. Both loopand fooare operating normally regardless, but it seems that I can not put them. How am I supposed to do this? Thanks in advance.

+5
source share
1 answer

, . /, (. ),

:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

 <xsl:template match="/">
    <xsl:call-template name="loop">
        <xsl:with-param name="times" select="3"/>
        <xsl:with-param name="output">
            <xsl:call-template name="foo">
                <xsl:with-param name="pN" select="5"/>
            </xsl:call-template>
        </xsl:with-param>
    </xsl:call-template>
 </xsl:template>

 <xsl:template name="loop">
  <xsl:param name="times" select="1"/>
  <xsl:param name="output" select="2"/>

  <xsl:choose>
      <xsl:when test="not($times > 0)">
       <xsl:value-of select="$output"/>
      </xsl:when>
      <xsl:otherwise>
       <xsl:call-template name="loop">
        <xsl:with-param name="times" select="$times -1"/>
        <xsl:with-param name="output" select="2*$output"/>
       </xsl:call-template>
      </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

 <xsl:template name="foo">
  <xsl:param name="pN" select="1"/>

  <xsl:value-of select="2*$pN"/>
 </xsl:template>
</xsl:stylesheet>

, XML ( ), , :

80

:

, .

( ) . , .

, :

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

 <xsl:template match="/">
   <xsl:variable name="vTwice">
    <xsl:call-template name="twice">
      <xsl:with-param name="pN" select="5"/>
    </xsl:call-template>
   </xsl:variable>

    <xsl:call-template name="loop">
        <xsl:with-param name="pTtimes" select="3"/>
        <xsl:with-param name="pN" select="$vTwice"/>
    </xsl:call-template>
 </xsl:template>

 <xsl:template name="loop">
  <xsl:param name="pTtimes" select="1"/>
  <xsl:param name="pN" select="2"/>

  <xsl:choose>
      <xsl:when test="not($pTtimes > 0)">
       <xsl:value-of select="$pN"/>
      </xsl:when>
      <xsl:otherwise>
       <xsl:call-template name="loop">
        <xsl:with-param name="pTtimes" select="$pTtimes -1"/>
        <xsl:with-param name="pN" select="2*$pN"/>
       </xsl:call-template>
      </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

 <xsl:template name="twice">
  <xsl:param name="pN" select="1"/>

  <xsl:value-of select="2*$pN"/>
 </xsl:template>
</xsl:stylesheet>
+9

All Articles