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/)將幫助你理解遞歸。 –