XSLT 1.0 convert the_brown_fox into | The Brown Fox |
My attempt:
<xsl:template name="GetDisplay">
<xsl:param name="input"/>
<xsl:text>|</xsl:text>
<xsl:call-template name="GetDisplay_1">
<xsl:with-param name="input" select="$input"/>
</xsl:call-template>
<xsl:text> |</xsl:text>
</xsl:template>
<xsl:template name="GetDisplay_1">
<xsl:param name="input"/>
<xsl:text> </xsl:text>
<xsl:call-template name="GetUpper">
<xsl:with-param name="input" select="substring($input,1,1)"/>
</xsl:call-template>
<xsl:vari开发者_开发知识库able name="head" select="substring-before($input,'_')"/>
<xsl:choose>
<xsl:when test="$head=''">
<xsl:value-of select="substring($input,2)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($head,2)"/>
<xsl:call-template name="GetDisplay_1">
<xsl:with-param name="input" select="substring-after($input,'_')"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="GetUpper">
<xsl:param name="input"/>
<xsl:value-of select="translate($input,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
</xsl:template>
Instead of having the need of 2 functions (GetDisplay and GetDisplay_1) i want to have only 1 function to accomplish the same result (we may leave the GetUpper intact of course).
Is it even possible?
PS: Strictly XSLT 1.0 thanks. (and no EXSLT / etc thanks)
Why not adding a parameter, to be used only on the first call?
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/test">
<xsl:call-template name="GetDisplay_1">
<xsl:with-param name="input" select="'the_brown_fox'"/>
<xsl:with-param name="start" select="'start'"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="GetDisplay_1">
<xsl:param name="input"/>
<xsl:param name="start" select="''"/>
<xsl:choose>
<xsl:when test="$start='start'">
<xsl:text>|</xsl:text>
<xsl:call-template name="GetDisplay_1">
<xsl:with-param name="input" select="$input"/>
</xsl:call-template>
<xsl:text> |</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
<xsl:call-template name="GetUpper">
<xsl:with-param name="input" select="substring($input,1,1)"/>
</xsl:call-template>
<xsl:variable name="head" select="substring-before($input,'_')"/>
<xsl:choose>
<xsl:when test="$head=''">
<xsl:value-of select="substring($input,2)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($head,2)"/>
<xsl:call-template name="GetDisplay_1">
<xsl:with-param name="input" select="substring-after($input,'_')"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="GetUpper">
<xsl:param name="input"/>
<xsl:value-of select="translate($input,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
</xsl:template>
</xsl:stylesheet>
精彩评论