XSL - 你如何将首字母大写 [英] XSL - How do you capitalize first letter
本文介绍了XSL - 你如何将首字母大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 xml.
<Name>
<First>john</First>
<Last>smith</Last>
</Name>
我想把第一个字母大写并用下面的格式输出.
I want to capitalize first letter and out put in following formate.
<FullName>John Smith</FullName>
提前致谢.
推荐答案
I.XSLT 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>
当此转换应用于提供的 XML 文档时:
<Name>
<First>john</First>
<Last>smith</Last>
</Name>
产生想要的、正确的结果:
<FullName>John Smith</FullName>
<小时>
二.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>
这篇关于XSL - 你如何将首字母大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文