0
这是关于反转字符串的全部内容。它适用于给定值“ABCDEF”。输出也是正确的'FEDCBA'。但我想知道这是如何在字符串中打印字母'A'和'D'的。任何人都可以帮助我理解这一点吗?请。 详细说明这个工作方法。子串值递归处理
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
<xsl:output method="html"/>
<xsl:template name="reverse">
<xsl:param name="input" select="'ABCDEF'"/>
<xsl:variable name="len" select="string-length($input)"/>
<xsl:choose>
<xsl:when test="$len < 2">
<xsl:value-of select="$input"/>
</xsl:when>
<xsl:when test="$len = 2">
<xsl:value-of select="substring($input,2,1)"/>
<xsl:value-of select="substring($input,1,1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="mid" select="floor($len div 2)"/>
<xsl:call-template name="reverse">
<xsl:with-param name="input" select="substring($input,$mid+1,$mid+1)"/>
</xsl:call-template>
<xsl:call-template name="reverse">
<xsl:with-param name="input" select="substring($input,1,$mid)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="/">
<xsl:call-template name="reverse">
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
什么是外呼的意思吗?我无法理解 – Sakthivel
只要输入长度大于2,模板就会自动调用输入的一半。 每当这些“自我调用”中的一个因为长度为2或更小而结束时,它将返回到上面的图层,这就是我所说的“外部呼叫”。 –
也许[this](http://www.ibm.com/developerworks/xml/library/x-xslrecur/)将帮助你理解递归。 –