Saturday 15 June 2013

xml - multiple CData to a single one -



xml - multiple CData to a single one -

i trying create xml transforming xml using xslt. problem is: using multiple "xsl:value of select=...." in single element, , marked element cdata element. value receive after transformation includes multiple cdata, while want them within single cdata.

for example: original xml:

<test> <text1>wow</text1> <text3>no</text3> </test>

xslt (there headers above have "bla" value cdata):

<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" > <xsl:output method="xml" cdata-section-elements="bla" /> <xsl:template match="/"> <bla id="bla"> text<xsl:value-of select="test/text1" />moretext<xsl:value-of select="test/text3" /> </bla> </xsl:template> </xsl:stylesheet>

output xml:

<?xml version="1.0" encoding="utf-8"?><bla id="bla"><![cdata[text]]><![cdata[wow]]><![cdata[moretext]]><![cdata[no]]></bla>

but, want in end this:

<?xml version="1.0" encoding="utf-8"?><bla id="bla"><![cdata[textwowmoretextno]]></bla>

anyone knows need alter accomplish this?

thanks!

i tried illustration saxon 6.5.5 , saxon 9.5, both output single cdata section

<?xml version="1.0" encoding="utf-8"?><bla id="bla"><![cdata[ textwowmoretextno]]></bla>

and @ to the lowest degree xslt 2.0 think http://www.w3.org/tr/xslt-xquery-serialization/#serdm "for each subsequence of adjacent text nodes in s5, re-create single text node new sequence equal values of text nodes in subsequence concatenated in order. text nodes values of 0 length dropped." prescribes the adjacent text nodes created should merged , cdata-section-elements serialization should single cdata section. if xslt processor utilize not file bug on it, workaround seek create single text xsl:value-of select="concat(...)", e.g. <bla id="bla"><xsl:value-of select="concat('text', test/text1, 'moretext', test/text3)"/></blah>.

xml xslt-2.0

No comments:

Post a Comment