2012-03-08 10 views
14

私は次のXMLを持っています。XSL - 最初の文字を大文字にするには

<Name> 
    <First>john</First> 
    <Last>smith</Last> 
</Name> 

私は最初の文字を大文字にし、次のformateで大文字にします。

<FullName>John Smith</FullName> 

ありがとうございます。

+1

[functx:大文字第](http://www.xsltfunctions.com/xsl/functx_capitalize-first.html) –

答えて

25

I. XSLT 2.0溶液:希望、正しい結果がを生成さ

<Name> 
    <First>john</First> 
    <Last>smith</Last> 
</Name> 

この変換が提供されるXML文書に適用され

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:template match="/*"> 
    <FullName><xsl:apply-templates/></FullName> 
</xsl:template> 

<xsl:template match="First|Last"> 
    <xsl:sequence select= 
    "concat(upper-case(substring(.,1,1)), 
      substring(., 2), 
      ' '[not(last())] 
     ) 
    "/> 
</xsl:template> 
</xsl:stylesheet> 

<FullName>John Smith</FullName> 

II。 XSLT 1.0溶液

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:variable name="vLower" select= 
"'abcdefghijklmnopqrstuvwxyz'"/> 

<xsl:variable name="vUpper" select= 
"'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/> 

<xsl:template match="/*"> 
    <FullName><xsl:apply-templates/></FullName> 
</xsl:template> 

<xsl:template match="First|Last"> 
    <xsl:value-of select= 
    "concat(translate(substring(.,1,1), $vLower, $vUpper), 
      substring(., 2), 
      substring(' ', 1 div not(position()=last())) 
     ) 
    "/> 
</xsl:template> 
</xsl:stylesheet> 
0

試行:

concat(
    translate(
    substring($Name, 1, 1), 
    'abcdefghijklmnopqrstuvwxyz', 
    'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 
), 
    substring($Name,2,string-length($Name)-1) 
) 
関連する問題