 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 14th, 2007, 05:11 AM
|
|
Registered User
|
|
Join Date: Dec 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Applying style to CDATA content
Hi guys,
Is it possible to apply templates to data contained within CDATA tags? E.g. if I have to following structure:
Code:
<somedata>
<![CDATA[Here some <link>somewhere</link>]]>
</somedata>
If I would like to apply a template to the <link> tag, would that be possible? If not, can anyone suggest a good work around?
Thanks!
|
|

December 14th, 2007, 05:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Not in a pure XSLT way as the data in a CDATA section is text, not mark up. That's why people advise against using CDATA in this way. In Saxon you could read the text, use the saxon:parse extension and then pass the value to a function for manipulation, or a named template if you're using version 1.0.
--
Joe ( Microsoft MVP - XML)
|
|

December 14th, 2007, 05:47 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
<link> isn't a tag, it's ordinary text. It would be a tag if it weren't in CDATA. The reason (the ONLY reason) for using CDATA is to tell the recipient that everying inside is to be treated as text, not as markup.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

December 14th, 2007, 07:03 AM
|
|
Registered User
|
|
Join Date: Dec 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That makes sense. However, if I would remove the CDATA tags and put HTML markup in there, like <br />, the markup seems to disappear in the output. ???
|
|

December 14th, 2007, 07:08 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Can you show an example of disappearing mark up? You'll need to detail how you're transforming and displaying etc.
--
Joe ( Microsoft MVP - XML)
|
|

December 14th, 2007, 07:10 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
If you use <xsl:copy-of> to copy the <somedata> node then it will retain all inner elements. If you are however using <xsl:value-of> then you are making a copy of the textual value of the somedata node, which doesn't include inner markup.
/- Sam Judson : Wrox Technical Editor -/
|
|

December 14th, 2007, 07:10 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>the markup seems to disappear in the output. ???
That usually means you used xsl:value-of - but expecting us to debug your code without showing your code is asking for a lot.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
 |