‎2009 Mar 25 10:10 AM
Hi,
I have a problem with formatting dynamic generated XML. I pass a dynamic DDIC-structure to an XSLT transformation and there I need to reformat some content:
I need to format decimal content of xml elements, example:
<element>9.2</element> needs to be <element>9,20<element>
Also, I need to clear out initial values, example:
<element>0.0</element> needs to be <element />
First I tried to use the xsl:decimal-format in the xslt-transformation but SAP did not support this function.
Here my plain and simple XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
Has anyone an idea how to reformat the content within the XML oder wihtin the iXML-framework?
Thank you & best regards,
Peter
‎2009 Mar 25 10:21 AM
Hi,
you can use a replace function:
fn:replace(string,pattern,replace)
Returns a string that is created by replacing the given pattern with the replace argument
Example: replace("Bella Italia", "l", "*")
Result: 'Be*a Itaia'
Example: replace("Bella Italia", "l", "")
Result: 'Bea Itaia'
‎2009 Mar 25 10:21 AM
Hi,
you can use a replace function:
fn:replace(string,pattern,replace)
Returns a string that is created by replacing the given pattern with the replace argument
Example: replace("Bella Italia", "l", "*")
Result: 'Be*a Itaia'
Example: replace("Bella Italia", "l", "")
Result: 'Bea Itaia'
‎2009 Mar 25 10:40 AM
Hi,
can I use this function within the xsl:copy-of or do I need to loop through all elements? And how can I prevent date formatted strings to be changed, too?
Thank you!
‎2009 Mar 25 10:45 AM
I think you should leave the "copy-of" out and place the "replace" functions there (you will need 2, one for the comma and one for the "0.00).
In "template-match" you need to select the path that needs to be changed. Then use the the replace functions with propper input values.
Regards,
Kai
‎2009 Mar 25 12:33 PM
Hm...
If I let the copy-of outside, i did not get the DDIC-data in.
Using the fn:replace()-function leads to unclosed element tag error...
And last not least I think that the template-match needs to be "/" because I can have a lot of elemets somewhere in the structure...
My current XSLT which does not work:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
<fn:replace(".","bla","blub")/>.
</xsl:template>
</xsl:stylesheet>
Another solution might be converting all DDIC decimal fields to char and reformat them in ABAP, but this is ugly...
Regards, Peter
‎2009 Mar 25 12:42 PM
Please check here:
http://www.w3schools.com/XSL/el_decimal-format.asp
XSLT can do it definetely!
Regards,
Kai
PS:
http://www.xml.com/pub/a/2002/06/05/transforming.html
http://www.xsltfunctions.com/xsl/functx_replace-element-values.html
might help also ;o)
Edited by: Kai Lerch-Baier on Mar 25, 2009 1:45 PM
‎2009 Mar 25 1:13 PM
Yes, XSLT can. But SAP does not support xsl:decimal-format, yippieh
Regards, Peter
‎2009 Mar 25 1:19 PM
Oh - did I get you wrong? I thought you'll do a XSLT transformation to format the data correctly.... - Not?!
Kai
‎2009 Mar 25 1:24 PM
Yes I want to format the content with XSLT... but within the SAP system. And SAP did not support everything... see here:
[http://help.sap.com/saphelp_nw04/Helpdata/de/e8/e7463c6796e61ce10000000a114084/content.htm|http://help.sap.com/saphelp_nw04/Helpdata/de/e8/e7463c6796e61ce10000000a114084/content.htm]
‎2009 Mar 25 1:26 PM
Okay :o(
then you may walk through the links above (they are really helpful) and determione with functions, that are supported by SAP, are usable. Good Luck!!!
Regards,
Kai