Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Formatting XML-Content

Former Member
0 Likes
1,299

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,157

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'

See http://www.w3schools.com/XPath/xpath_functions.asp

9 REPLIES 9
Read only

Former Member
0 Likes
1,158

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'

See http://www.w3schools.com/XPath/xpath_functions.asp

Read only

0 Likes
1,157

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!

Read only

0 Likes
1,157

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

Read only

0 Likes
1,157

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

Read only

0 Likes
1,157

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

Read only

0 Likes
1,157

Yes, XSLT can. But SAP does not support xsl:decimal-format, yippieh

Regards, Peter

Read only

0 Likes
1,157

Oh - did I get you wrong? I thought you'll do a XSLT transformation to format the data correctly.... - Not?!

Kai

Read only

0 Likes
1,157

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]

Read only

0 Likes
1,157

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