利用xslt与xml实现具体字段字母的大小写转换

定义一个全局的变量

<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大写,也可以利用此函数
---------------------
作者:joke331
来源:CSDN
原文:https://blog.csdn.net/ApplicationJoke/article/details/82384731
版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2019-02-17 16:54  darling331  阅读(175)  评论(0编辑  收藏  举报