Florian Rengers wrote: > i have XML included in CDATA and have to transform that xml like. > > I have to transform this XML: > <record> > <core> > <![CDATA[ > <Polygon> > <coordinates>4408580,5547914 4408570,5547514 4408580,5747085 > 4716183,5747085 4716193,5547514 4716183,5547914 > 4408580,5547914</coordinates> > </Polygon> > ]]> > <core> > </record> > > into this XML: > <record> > <box> > <x1>4408580</x1> > <y1>5547914</y1> > <x2>4716183</x2> > <y2>5747085</y2> > </box> > <record>
A CDATA section denotes character data -- unstructured text -- not elements or attributes or comments or processing instructions or any other kind of information. Generally the solution to this problem is to attack it at the source: don't call it CDATA if it has structure, especially if you're going to be treating it as structured data. If you intend to parse it, there's no reason to have it in a CDATA section. The alternative is to write an XSLT extension function to produce a document fragment from a string. It needs to accept an XPath string object argument (well, convert whatever it gets into a string), parse it (probably with a dummy element's start and end tags around it) and return a node-set (of the dummy element node's children). See http://xml.apache.org/xalan-j/extensions.html for info about writing extensions for Xalan-J.