定义一个全局的变量
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" /> <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
利用 translate函数进行数据转换
例如:
<?xml version="1.0" encoding="utf-8"?>
<shipment>
<header>
<shipmentHeader>
<sourceOrderCode>1-8hldi</sourceOrderCode>
</shipmentHeader>
</header>
</shipment>
===============================================================
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:template match="/">
<ListOfFtCsmPartsApproveIoWms>
<FtCsmPartsApprove>
<xsl:apply-templates select="//shipment/header/shipmentHeader"/>
</FtCsmPartsApprove>
</ListOfFtCsmPartsApproveIoWms>
</xsl:template>
<xsl:template match="/shipment/header/shipmentHeader">
<Id><xsl:value-of select="translate(sourceOrderCode,$smallcase,$uppercase)"/></Id>
</xsl:template>
</xsl:stylesheet>
============================================================
<?xml version="1.0" encoding="utf-16"?><ListOfFtCsmPartsApproveIoWms><FtCsmPartsApprove><Id>1-8HLDI</Id></FtCsmPartsApprove></ListOfFtCsmPartsApproveIoWms>
转换完之后,得到结果,会将小写转为大写
原理是translate的函数,将参数1余参数2匹配,在与参数3匹配,并留存参数3的值,
转换123456789大写,也可以利用此函数
本文展示了如何利用XSLT和XML来转换特定字段的字母大小写。通过定义全局变量并应用translate函数,实现了将sourceOrderCode字段的小写字母转换为大写。转换后,源订单代码从'1-8hldi'变为'1-8HLDI',演示了translate函数的工作原理。
25

被折叠的 条评论
为什么被折叠?



