使用XSL在SOAP消息中重新格式化日期时间但是会出错

时间:2017-04-19 20:53:43

标签: xml xslt soap

我是XSL和SOAP消息的新手,所以请善待。我试图创建一个XSL来重新格式化SOAP消息中的一些元素,但我没有运气成功。我得到的一般错误是无法转换:文档末尾的额外内容。我一直在努力阅读这意味着什么,而且对我来说并没有多大意义。如果有人能帮助我做错了什么,我将永远感激不尽!

这是我的XML:

<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<Get__CompIntfc__VNDR_IDResponse xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/M5540000.V1">
<SETID>SKSK</SETID>
<CREATED_DTTM>1900-01-01T00.00.00.000000</CREATED_DTTM>
</Get__CompIntfc__VNDR_IDResponse>
</soapenv:Body>
 </soapenv:Envelope>

这是我的XSL:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m="http://www.example.org/stock" version="1.0">

  <xsl:template match="//soapenv:body/m:Get__CompIntfc__VNDR_IDResponse/*">
      <xsl:apply-templates/>
  </xsl:template>

<xsl:template match="CREATED_DTTM">
     <xsl:element name="CREATED_DTTM">
         <xsl:call-template name="formatdate">
             <xsl:with-param name="datestr" select="."/>
        </xsl:call-template>
     </xsl:element>
  </xsl:template>

<xsl:template name="formatdate">
     <xsl:param name="datestr"/>
    <xsl:variable name="date">
       <xsl:value-of select="substring($datestr,1,13)"/>
    </xsl:variable>

    <xsl:variable name="mm">
       <xsl:value-of select="substring($datestr,15,2)"/>
    </xsl:variable>

    <xsl:variable name="ss">
       <xsl:value-of select="substring($datestr,18,2)"/>
    </xsl:variable>

     <xsl:variable name="msec">
       <xsl:value-of select="substring($datestr,21,6)"/>
    </xsl:variable>



    <xsl:value-of select="$date"/>
    <xsl:value-of select="':'"/>
    <xsl:value-of select="$mm"/>
    <xsl:value-of select="':'"/>
    <xsl:value-of select="$ss"/>
    <xsl:value-of select="':'"/>
    <xsl:value-of select="$msec"/>
  </xsl:template>



  <xsl:template match="node()|@*"> 
     <xsl:copy> 
         <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>

  </xsl:template>

</xsl:stylesheet>

0 个答案:

没有答案