I had a challenge with creating some CDATA elements for a customer.
In XML you can use CDATA if you have some escaped content in some of your document. If there is the CDATA start and end tag then it does not have any problem with containing characters like “< >” . These characters will normally create problems with XML because it is what is expected in the formatting.
Let’s say we have a document that looks like the following XML document.
As we can see the text in this document is escaped, so a potential recipient needs to escape it to be able to display the result.
And we want it to be transformed into. As seen the %lt; is converted into <, so the content can be displayed as HTML really easy.
In XSL it can be done in the following way.
In this example we are using the cdata-section-elements on the output target. This command tells parser to escape the result in the text element with cdata. This works when I’m doing XSL standalone SAPXMLTOOLKIT. Unfortunately it did not work when I was testing it at the PI system. So I had to find another solution. I don’t know if it was just me, or this feature is not supported.
The match “@*|node()” area makes sure that both attributes and value elements are copied. If only “*” was used then there the attributes would not be copied.
I therefore had to try again. It is not that much different.
In this section we matched the text element. The element is copied with the copy statement.
The text is escaped with the disable-output-escaping, to make sure that the values is not escaped. To make this work, the first < in the CDATA had to be using an escaped value. If not then all the content in the CDATA section would just be copied to the result, it will not be evaluated.
I hope that this is helpful for you to make get more knowledge about what is going on.