on 11-10-2009 9:09 AM
Hi All,
I am having a requirement where i have to fill the attribute value of a element depending upon the values coming from source and do the date conversions using XSLT mapping. The source and target structures are like that:
Target Structure is:
<InvoiceHeader> (Record)
<VBELN> (element)
<FKDAT> (date element dd/mm/yyyy)
Target Structure:
<InvoiceDetailRequestHeader>(Element)
<invoiceID> (Atrribute) mapped to <VBELN>
<invoice date> (Attribute) mapped to <FKDAT>
The target XSD should come like this:
<InvoiceDetailRequestHeader invoiceID="2100204628" purpose="standard" operation="new" invoiceDate="2009-10-31T00:00:00+5:30">
Request you all to help.
Thanks
Amit
Hi ,
I have written few days back to convert time date format in XSLT Mapping,Its working fine in my requirement,
add below code ,if its required change according to your format and append to you xslt ,but if you are adding any JAVA function to your XSLT then you need to add definition of XSLt like below
<xsl:stylesheet version="1.0" xmlns:java="http://xml.apache.org/xslt/java" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="java">
<!--<xsl:template name="GetDateFromLocal" xmlns:cal="xalan://java.util.GregorianCalendar">
* <xsl:param name="Date"/>*
* <xsl:param name="Time"/>*
* <xsl:param name="TimeZone"/>*
* <xsl:variable name="YYYY" select="substring($Date,1,4)"/>*
* <xsl:variable name="MM" select="substring($Date,5,2) - 1"/>*
* <xsl:variable name="DD" select="substring($Date,7,2)"/>*
* <xsl:variable name="hh" select="substring($Time,1,2)"/>*
* <xsl:variable name="mm" select="substring($Time,3,2)"/>*
* <xsl:variable name="ss" select="substring($Time,5,2)"/>*
* <xsl:variable name="today_formatted" select="java:java.text.SimpleDateFormat.new('yyyyMMdd')"/>*
* <xsl:variable name="time_formatted" select="java:java.text.SimpleDateFormat.new('HHmmss')"/>*
* <xsl:variable name="timezone" select="java:java.util.TimeZone.getTimeZone($TimeZone)"/>*
* <xsl:variable name="zone" select="java:getRawOffset($timezone)"/>*
* <xsl:variable name="rightNow" select="cal:getInstance()"/>*
* <xsl:variable name="DateToUse" select="cal:set($rightNow,$YYYY,$MM,$DD,$hh,$mm,$ss)"/>*
* <xsl:variable name="time" select="cal:getTimeInMillis($rightNow)"/>*
* <xsl:variable name="date" select="number(string($time) - string($zone))"/>*
* <xsl:value-of select="java:format($today_formatted, $date)"/>T<xsl:value-of select="java:format ($time_formatted, $date)"/>*
* </xsl:template>-->*
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
<InvoiceDetailRequestHeader invoiceID="2100204628" purpose="standard" operation="new" invoiceDate="2009-10-
31T00:00:00+5:30">
The target structure does not seem to have purpose and operation attributes....are they constants which you need to map?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Abhishek,
The purpose and operation attributes needs to be hard coded so i havent mentioned in my structure. The complete structure is:
Target Structure:
<InvoiceDetailRequestHeader>(Element)
<invoiceID> (Atrribute) mapped to <VBELN>
<invoice date> (Attribute) mapped to <FKDAT>
<purpose> (Attribute) hard coded with value standard
<operation> (Attribute) hard coded with value new
Thanks
Amit Srivastava
The only thing that you need to work on is converting the input date into the required format (2009-10-31T00:00:00+5:30)....i think you will just receive YYYY-MM-DD and you need to write a JAVA code in your XSLT mapping to get the output as
YYYY-MM-DDTHH:MM:SS+-Offset .... standard XSLT functions are not capable to achieve this....java mapping needs to be implemented.....the mapping for other attributes is direct mapping to source or mapping with a constant
Regards,
Abhishek.
Hi,
Thanks Abhishek/Raj for ur reply.
Abhishek... What do u mean by this??
"The mapping for other attributes is direct mapping"
Actually i am trying to use XSLT like this:
<InvoiceDetailRequestHeader>
<xsl:attribute name='invoiceID'><xsl:value-of select="ns0:MT_OTR/InvoiceHeader/VBELN"/></xsl:attribute>
</InvoiceDetailRequestHeader>
So that the invoice id attribute has the value of VBELN coming from the source. But this is not working. Is there any other alternative for this.
Thanks
Amit Srivastava
Check piece of example from w3schools on how to make a XSLT mapping for attribute:
http://www.w3schools.com/xsl/el_attribute.asp
instead of using single-quote use double-quotes and give the full path of the source field in the xsl:value-of select
Also I hope that you have declared invoiceID , purpose , operation , invoicedate as attributes in the target structure (in the DT)
Regards,
Abhishek.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.