0

I am very new to xslt programming. Can any one help with this:

input xml:

<?xml version="1.0" encoding="UTF-8"?>
<MESSAGE>
    <ER>
        <MXITEMOUT xmlns="http://www.mro.com/mx/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" language="EN">
            <Header operation="Notify" event="1">
                <SenderID type="MAXIMO" majorversion="6" minorversion="0" build="02" dbbuild="V600-76">MX</SenderID>
                <CreationDateTime>2005-08-15T14:28:06-05:00</CreationDateTime>
                <RecipientID>EXTSYS1234</RecipientID>
                <MessageID>1124</MessageID>
            </Header>
            <Content>
                <MXITEM>
                    <ITEM action="Add">
                        <ITEMNUM>I1001</ITEMNUM>
                        <DESCRIPTION langenabled="1">test item</DESCRIPTION>
                        <ROTATING>1</ROTATING>
                        <LOTTYPE maxvalue="NOLOT">NOLOT</LOTTYPE>
                        <CAPITALIZED>0</CAPITALIZED>
                        <CREATEDDATE>2014-05-22T13:00:46+10:00</CREATEDDATE>
                    </ITEM>
                </MXITEM>
            </Content>
        </MXITEMOUT>
    </ER>
    <IR>
        <MXITEMOUT xmlns="http://www.mro.com/mx/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" language="EN">
            <Header operation="Notify" event="1">
                <SenderID type="MAXIMO" majorversion="6" minorversion="0" build="02" dbbuild="V600-76">MX</SenderID>
                <CreationDateTime>2005-08-15T14:28:06-05:00</CreationDateTime>
                <RecipientID>EXTSYS1234</RecipientID>
                <MessageID>1124</MessageID>
            </Header>
            <Content>
                <MXITEM>
                    <ITEM action="Add">
                        <ITEMNUM>I1001</ITEMNUM>
                        <DESCRIPTION langenabled="1">test item</DESCRIPTION>
                        <ROTATING>1</ROTATING>
                        <LOTTYPE maxvalue="NOLOT">NOLOT</LOTTYPE>
                        <CAPITALIZED>0</CAPITALIZED>
                        <CREATEDDATE>2014-05-22T13:00:46+10:00</CREATEDDATE>
                    </ITEM>
                </MXITEM>
            </Content>
        </MXITEMOUT>
    </IR>
</MESSAGE>

My XSLT is:

<?xml version="1.0"?> 
<!-- 
This XSL is supposed to change the ITEMNUM tag value by prepending 001 to the existing value.
It also strips off the MESSAGE and IR wrapper tags so that the resultant data is consistent with 
our XML schema
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mro="http://www.mro.com/mx/integration" version="1.0" exclude-result-prefixes="mro">

<xsl:template match="/MESSAGE">
    <xsl:apply-templates select="IR"/>
</xsl:template>
<xsl:template match="IR">
    <xsl:apply-templates select="@*|*|text()"/>
</xsl:template>

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

<!-- 
Change the ITEMNUM tag value by prepending 001 to the existing value
-->
<xsl:template match="mro:ITEMNUM">  
    <xsl:element name="ITEMNUM" namespace="http://www.mro.com/mx/integration">  
    <xsl:text>MAX-</xsl:text><xsl:value-of select="."/>
    </xsl:element>
</xsl:template>

</xsl:stylesheet>

Current output is:

<?xml version="1.0" encoding="UTF-8"?>
        <MXITEMOUT xmlns="http://www.mro.com/mx/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" language="EN">
            <Header operation="Notify" event="1">
                <SenderID type="MAXIMO" majorversion="6" minorversion="0" build="02" dbbuild="V600-76">MX</SenderID>
                <CreationDateTime>2005-08-15T14:28:06-05:00</CreationDateTime>
                <RecipientID>EXTSYS1234</RecipientID>
                <MessageID>1124</MessageID>
            </Header>
            <Content>
                <MXITEM>
                    <ITEM action="Add">
                        <mro:ITEMNUM xmlns:mro="http://www.mro.com/mx/integration">MAX-I1001</mro:ITEMNUM>
                        <DESCRIPTION langenabled="1">test item</DESCRIPTION>
                        <ROTATING>1</ROTATING>
                        <LOTTYPE maxvalue="NOLOT">NOLOT</LOTTYPE>
                        <CAPITALIZED>0</CAPITALIZED>
                        <CREATEDDATE>2014-05-22T13:00:46+10:00</CREATEDDATE>
                    </ITEM>
                </MXITEM>
            </Content>
        </MXITEMOUT>

Expected output is:

<?xml version="1.0" encoding="UTF-8"?>
        <MXITEMOUT xmlns="http://www.mro.com/mx/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" language="EN">
            <Header operation="Notify" event="1">
                <SenderID type="MAXIMO" majorversion="6" minorversion="0" build="02" dbbuild="V600-76">MX</SenderID>
                <CreationDateTime>2005-08-15T14:28:06-05:00</CreationDateTime>
                <RecipientID>EXTSYS1234</RecipientID>
                <MessageID>1124</MessageID>
            </Header>
            <Content>
                <MXITEM>
                    <ITEM action="Add">
                        <mro:ITEMNUM xmlns:mro="http://www.mro.com/mx/integration">MAX-I1001</mro:ITEMNUM>
                        <DESCRIPTION langenabled="1">test item</DESCRIPTION>
                        <ROTATING>1</ROTATING>
                        <LOTTYPE maxvalue="NOLOT">NOLOT</LOTTYPE>
                        <CAPITALIZED>0</CAPITALIZED>
                        <CREATEDDATE>2014-05-22T23:00:46.000Z</CREATEDDATE>
                    </ITEM>
                </MXITEM>
            </Content>
        </MXITEMOUT>

I am trying find logic in google to convert date to utc format in xslt.

It is throwing strange errors.

XML date:2014-05-22T13:00:46+10:00 Expected Date: 2014-05-22T23:00:46.000Z

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • It's hard to visually diff the expected and actual outputs. Could you call out the differences? Something to do with timezone offsets? – Mike Samuel Feb 19 '16 at 05:12
  • Actually createddate in xml is 2014-05-22T13:00:46+10:00 and expected output is 2014-05-22T23:00:46.000Z. I tried to use by defining createDate as variable. but no luck, error is "Cannot format given Object as a Date" – Srikanth Reddy Feb 19 '16 at 05:22
  • 1
    To do date/time handling in XSLT, you really ought to move to XSLT 2.0 if you possibly can. And if you ask questions about the old version 1.0, you should label them as such. – Michael Kay Feb 19 '16 at 08:54
  • ok @Michael Kay, i will try with xslt 2.0 – Srikanth Reddy Feb 21 '16 at 22:40

0 Answers0