2011-06-24 12 views
1

私の試み:私は同じ結果を達成するために1つだけの機能を持つようにしたいの代わりに2つの機能(GetDisplayGetDisplay_1)の必要性を持っていることのXSLT 1.0はthe_brown_foxを|ブラウン・フォックス|

<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: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:template> 

<xsl:template name="GetUpper"> 
    <xsl:param name="input"/> 
    <xsl:value-of select="translate($input,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/> 
</xsl:template> 

(私たちは無傷でGetUpperを残すことができますもちろん)。

それは可能ですか?

PS:厳密にXSLT 1.0に感謝します。 (とEXSLT/etcありがとう)

答えて

1

最初の呼び出しでのみ使用するパラメータを追加してみませんか?

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

nice。それを考えなかった= D – Troy

関連する問題