Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old December 14th, 2007, 05:11 AM
Registered User
 
Join Date: Dec 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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!


 
Old December 14th, 2007, 05:21 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old December 14th, 2007, 05:47 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<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
 
Old December 14th, 2007, 07:03 AM
Registered User
 
Join Date: Dec 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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. ???


 
Old December 14th, 2007, 07:08 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old December 14th, 2007, 07:10 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
 
Old December 14th, 2007, 07:10 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a CDATA section; add nodeset to CDATA section kssudhish XSLT 3 January 3rd, 2008 07:13 AM
Applying discount blkskullwork Javascript 1 January 11th, 2007 05:14 PM
Choosing content depending on content of other ele dsekar_nat XSLT 1 February 27th, 2006 05:58 AM
problem applying a style to a webcontrol ACE2084 VS.NET 2002/2003 3 March 10th, 2005 02:10 PM
difference between style.visibility and style.disp Mimi Javascript How-To 6 September 17th, 2003 11:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.