xml – XSL – 你如何利用第一个字母
发布时间:2020-12-16 07:42:29 所属栏目:百科 来源:网络整理
导读:我有以下xml. Name Firstjohn/First Lastsmith/Last/Name 我想把首字母大写,并把它放在下面. FullNameJohn Smith/FullName 先谢谢你. I. XSLT 2.0解决方案: xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:output omi
|
我有以下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>
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
