我有以下xml.
<Name> <First>john</First> <Last>smith</Last> </Name>
我想把首字母大写,并把它放在下面.
<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>
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),$vLower,$vUpper),substring(' ',1 div not(position()=last())) ) "/> </xsl:template> </xsl:stylesheet>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。