日期格式的XSLT转换[2100-10-10T23:59:59.000Z];添加GMT时区

时间:2017-05-01 09:47:36

标签: xml xslt xslt-1.0

我是XSLT转换的新手,面临XSLT转换的问题。

<?xml version="1.0" encoding="UTF-8"?>
<parent>
<headers>
    <status>Success</status>
    <requestTime>2017-10-10T23:59:59.000Z</requestTime>
    <Date>2500-10-10T23:59:59.000Z</Date>
</headers>
<results>
    <partyId></partyId>
    <contId></contId>
    <identifier>
        <number>987651435</number>
        <type>SSN</type>
        <status>PRIMARY</status>
        <expiryDate>2100-10-10T23:59:59.000Z</expiryDate>
    </identifier>
    <identifier>
        <number>123456789</number>
        <type>CL</type>
        <status>SECONDARY</status>
        <expiryDate>2100-10-10T10:00:59.000Z</expiryDate>
    </identifier>
    <address>
        <street>Anantha Nagar Phase 2</street>
        <city>Bangalore</city>
        <country>
            <code>IN</code>
        </country>
        <state>
            <code>KA</code>
        </state>
    </address>
    <officerNo>7654345</officerNo>
    <entityCode>005</entityCode>
    <birthDate>1991-12-13T01:01:00.000Z</birthDate>
</results>

我希望转换所有与所提供日期的正则表达式匹配的值的标签,并在末尾添加时区,即+00:00而不是Z.

请您提供有关上述内容的任何意见。

1 个答案:

答案 0 :(得分:0)

这可能会有所帮助。您必须确定要与日期连接的时区值,因为它未在XML中指定。

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt">

<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" />

  <!-- To match the date pattern, key off of some of the constants in the date string. 
       (The below match uses only some of the constants.)
  -->
  <xsl:template match="*[substring(.,5,1)='-' and substring(.,8,1)='-'  and substring(.,14,1)=':']">
    <xsl:copy>
      <!-- Do transform here. Below is an example. -->
      <xsl:value-of select="concat(substring-before(.,'Z'), '+00:00')"/>
    </xsl:copy>
  </xsl:template>

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

</xsl:stylesheet>