.
XSL query - Grin with cat attached
Previous Entry Next Entry
XSL query Sep. 26th, 2005 01:25 pm
I need to insert a bunch of CDATA sections around certain XML tags with XSLT (I want to be able to use a stream parser on the resulting data and treat various parts as CDATA rather than tags & content). However I can't get the CDATA block in there without it stopping XSL processing (unsurprisingly enough) or breaking the XSL

Best attempt is:

<xsl:template match="flashXML|text">
<xsl:copy>
<![CDATA[<![CDATA[]]>
<xsl:apply-templates />
<![CDATA[]]]]><![CDATA[>]]>
</xsl:copy>
</xsl:template>


but then my output is &lt;![CDATA[...

Anyone help with this? I'm really not having a great day after last night's lack of sleep and XSL is far too new to me...
Tags:

From: valkyriekaren
Date: September 26th, 2005 - 12:36 pm (Link)
Poor babe.

Here, have an incredibly badly-designed website to mock:
http://www.triumph.com/uk/

(caution: contains underwear, Flash, makes noise)
From: flewellyn
Date: September 26th, 2005 - 11:26 pm (Link)
Egads, Karen! Where did you find such hideousness?!
From: ciphergoth
Date: September 26th, 2005 - 01:07 pm (Link)
There is no way to include a CDATA section in XSL output. Semantically, CDATA sections are just the same as having the same content inline and appropriately escaped, so that's what XSL will give you. Sorry.
From: babysimon
Date: September 26th, 2005 - 01:50 pm (Link)
Semantically, CDATA sections are just the same as having the same content inline and appropriately escaped

True.

There is no way to include a CDATA section in XSL output.

Maybe false.

I have not tried this, but I believe

<xsl:output cdata-section-elements="text"/>


at the beginning of your XSLT will ensure that all "text" nodes will have their contents CDATA'ed.

[PS: sorry about the comment spam, not awake today...]
From: ciphergoth
Date: September 26th, 2005 - 01:54 pm (Link)
From which we conclude that the index in this O'Reilly book is shit. It mentions this flag but it's not in the index under CDATA. Anyway, yes, SimonChisel has the right solution here.
From: babysimon
Date: September 26th, 2005 - 01:58 pm (Link)
...if the right solution is to CDATA every such element. If not, wechsler is screwed.

Oh dear, my distaste for XSL is starting to show through. Better shut up...
From: ciphergoth
Date: September 26th, 2005 - 02:03 pm (Link)
XSL sucks - I don't think you'll get any disagreement here. XML Output Method explains exactly what it does. Why didn't they just define an <xml:cdata> element?
From: babysimon
Date: September 26th, 2005 - 02:10 pm (Link)
Maybe they were too busy adding sockets support to SVG?
From: ciphergoth
Date: September 26th, 2005 - 02:14 pm (Link)
AAAAARGH!
From: reddragdiva
Date: September 26th, 2005 - 04:05 pm (Link)
*sporks eyes out*

Now I understand why SVG uploads to Wikimedia required a suitable cleanser to be written first.
From: babysimon
Date: September 26th, 2005 - 04:11 pm (Link)
That's only in 1.2, which is not a Recommendation yet. But yeah, SVG: nice idea, somewhat over-executed.
From: reddragdiva
Date: September 26th, 2005 - 04:16 pm (Link)
I suspect the cleansable SVG Lite will become the default standard and the rest can wander off to the happy land of "policy, not mechanism" with the curlier backwaters of CSS. This is why "no spec without a reference implementation and no reference implementation without a spec" is a good idea.
From: ciphergoth
Date: September 26th, 2005 - 02:07 pm (Link)
From: wechsler
Date: September 26th, 2005 - 02:48 pm (Link)
Well, that's fairly apt for XSL - and seems to have worked. Ick.

Many thanks to both of you.
From: flewellyn
Date: September 26th, 2005 - 04:39 pm (Link)
And people wonder why I hate XML and all its spawn...
From: ciphergoth
Date: September 26th, 2005 - 05:21 pm (Link)
Look at "external entity attack" and "entity expansion attack" for more reasons to hate it.
From: flewellyn
Date: September 26th, 2005 - 11:24 pm (Link)
I could just stick with "s-expressions done wrong" and "verbosity does not equal readability".