2014 Mar 30 7:56 AM
Hi Folks
I am working on developing a custom simple transformation, the requirement is convert the upload the file(unknown columns text file) into xml code.
here columns text has not been mentioned so while uploading this data using "upload" function module we can get into string table, so now I want to pass this data into transformation to convert into below format, can you please suggest me how can I do this.
<Template1>
<Name>first 10 characters in the file line1</Name>
<Address>character 11 to 40 in the file line1</Address>
<Salar>character 41 to 50 in the file line1</Salary>
.
.
.
Etc.,
</Template1>
Please suggest me how to split the file line 1 data based on my tags in the simple transformation.
Appreciate your help on this.
Regards,
Naresh.
2014 Apr 07 8:18 AM
Have a look at this snippet.
Substring function is used with offset/length to extract the substring , which is then populated into xml node.
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<root>
<xsl:apply-templates select="//*/item"/>
</root>
</xsl:template>
<xsl:template match="item">
<Template1>
<one>
<xsl:value-of select="substring(concat(., ''), 1, 1)"/>
</one>
<two>
<xsl:value-of select="substring(concat(., ''), 2, 2)"/>
</two>
<three>
<xsl:value-of select="substring(concat(., ''), 4, 3)"/>
</three>
<four>
<xsl:value-of select="substring(concat(., ''), 7, 4)"/>
</four>
<five>
<xsl:value-of select="substring(concat(., ''), 11, 5)"/>
</five>
</Template1>
</xsl:template>
</xsl:transform>
<?xml version="1.0" encoding="utf-8" ?>
<root>
<Template1>
<one>1</one>
<two>12</two>
<three>123</three>
<four>1234</four>
<five>12345</five>
</Template1>
<Template1>
<one>4</one>
<two>45</two>
<three>456</three>
<four>4567</four>
<five>45678</five>
</Template1>
</root>
/.
2014 Mar 30 8:10 AM
The simplest way is to convert your data first into an internal table with fields for name, address, salary etc.
Then use:
DATA my_output_xml TYPE string.
CALL TRANSFORMATION id RESULT xml my_output_xml SOURCE data = internal_table.
2014 Apr 02 12:09 AM
Hi Matthrew,
I was also thinking on this simple solution.
If I could make the entirething(spliting xml into internal table and convert them into xml tags format) with in the transformation so that I don't need to make any changes in the program side.
I hope I need to get expertise on this xml so that I can wrote my own code.
Anyhow thanks for your reply on this.
Regards,
naresh.
2014 Apr 07 8:18 AM
Have a look at this snippet.
Substring function is used with offset/length to extract the substring , which is then populated into xml node.
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<root>
<xsl:apply-templates select="//*/item"/>
</root>
</xsl:template>
<xsl:template match="item">
<Template1>
<one>
<xsl:value-of select="substring(concat(., ''), 1, 1)"/>
</one>
<two>
<xsl:value-of select="substring(concat(., ''), 2, 2)"/>
</two>
<three>
<xsl:value-of select="substring(concat(., ''), 4, 3)"/>
</three>
<four>
<xsl:value-of select="substring(concat(., ''), 7, 4)"/>
</four>
<five>
<xsl:value-of select="substring(concat(., ''), 11, 5)"/>
</five>
</Template1>
</xsl:template>
</xsl:transform>
<?xml version="1.0" encoding="utf-8" ?>
<root>
<Template1>
<one>1</one>
<two>12</two>
<three>123</three>
<four>1234</four>
<five>12345</five>
</Template1>
<Template1>
<one>4</one>
<two>45</two>
<three>456</three>
<four>4567</four>
<five>45678</five>
</Template1>
</root>
/.
2014 Apr 07 11:06 PM