2012-03-08 69 views
14

Tengo xml siguiente.XSL - ¿Cómo se escribe en mayúscula la primera letra

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

Quiero poner en mayúscula la primera letra y colocarla en el formato siguiente.

<FullName>John Smith</FullName> 

Gracias de antemano.

+1

[functx: capitalizar-primero] (http://www.xsltfunctions.com/xsl/functx_capitalize-first.html) –

Respuesta

25

I. XSLT solución 2,0:

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

cuando se aplica esta transformación en el documento previsto XML:

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

el resultado deseado, correcta se produce:

<FullName>John Smith</FullName> 

II. XSLT 1.0 solución:

<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

Probar:

concat(
    translate(
    substring($Name, 1, 1), 
    'abcdefghijklmnopqrstuvwxyz', 
    'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 
), 
    substring($Name,2,string-length($Name)-1) 
) 
Cuestiones relacionadas