1

I am performing XSLT transformation on some input XML which is generated from a FlatFile. I want to change the datatype of a element to "date" but without showing it in output XML.

Input XML:

<PostingDate>20141009</PostingDate>

XSLT Transformation:

<cdm:PostingDate>
    <xsl:attribute name="name"> 
       <xsl:value-of select="PostingDate"/>
    </xsl:attribute>
    <xsl:attribute name="type">xs:decimal</xsl:attribute>
</cdm:PostingDate>

Current Output:

<cdm:PostingDate name="20141009" type="xs:decimal"/>

Required Output:

<cdm:PostingDate>2014-10-09</cdm:PostingDate>

Note: Similarly I want to do some other transformations like to convert some XML elements into decimal and strings. Is it possible in XSLT 2.0?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
omer khalid
  • 855
  • 1
  • 12
  • 39

1 Answers1

2

I want to change the data type of a element to "date" but without showing it in output xml.

That's a rather meaningless wish, since the output does not carry the data type with it, and you don't need the data type during the processing (at least I don't see that you do). Why don't you do simply:

<cdm:PostingDate>
    <xsl:value-of select="concat(substring(PostingDate, 1, 4), '-', substring(PostingDate, 5, 2), '-', substring(PostingDate, 7, 2))"/>
</cdm:PostingDate>

Edit:

what i meant to say was that it is a some sort of pipe.

AFAIK, if you do:

<cdm:PostingDate>
    <xsl:sequence select="xs:date(concat(substring(PostingDate, 1, 4), '-', substring(PostingDate, 5, 2), '-', substring(PostingDate, 7, 2)))"/>
</cdm:PostingDate>

then the data type of <cdm:PostingDate> will remain xs:date until the output is serialized.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • You are right, output does not carry data type but after this conversion my CDM XML will be input for another process.And in that process they require some XML elements type as string,decimal or date type. So how would i achieve that..?. This XML is generated form a FLatFile so it just contains tags, nothing else no type definition. – omer khalid Nov 11 '14 at 05:07
  • @omerkhalid "*after this conversion my CDM XML will be input for another process.*" Will it be input after saving to a file, or within some sort of a pipe? – michael.hor257k Nov 11 '14 at 05:09
  • well the CDM XML will be publish over a JMS Queue from where the other service will pick it up. – omer khalid Nov 11 '14 at 06:33
  • @omerkhalid I am afraid that means nothing to me. – michael.hor257k Nov 11 '14 at 08:35
  • what i meant to say was that it is a some sort of pipe. – omer khalid Nov 11 '14 at 11:46