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 April 6th, 2007, 03:30 AM
Authorized User
 
Join Date: Apr 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Removing namespaces without escaping CDATA???

I' trying to remove namespaces from a document using the following piece of code that although works, has the side-effect of escaping CDATA sections (eg. "<![CDATA[blah blah]]>").

How can I prevent CDATA from being escaped..?

--- Begin xsl ---
<?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" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="*">

      <xsl:element name="{local-name()}">

        <xsl:for-each select="@*">

          <xsl:attribute name="{local-name()}">
            <xsl:value-of select="."/>
          </xsl:attribute>
        </xsl:for-each>
        <xsl:apply-templates/>
      </xsl:element>
  </xsl:template>
</xsl:stylesheet>
--- End xsl ---
 
Old April 6th, 2007, 05:51 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to show what your input looks like. If it were really a CDATA section like this:

<e:elem><![CDATA[text]]></e:elem>

then I would expect it to come out like this:

<elem>text</elem>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 6th, 2007, 12:28 PM
Authorized User
 
Join Date: Apr 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My input is like this:

Code:
<?xml version="1.0" encoding="utf-8"?>
   <jasperReport xmlns:sql="blahblah" name="dbreport">
      <queryString>
         <![CDATA[select name from patpat]]>
      </queryString>
      <field class="java.lang.String" name="name"/>
      ...
      <text><![CDATA[chr]]></text>
      ...
and the output I get from the above XSL code is:

Code:
<?xml version="1.0" encoding="utf-8"?>
   <jasperReport name="dbreport">
      <queryString>
         &lt;![CDATA[select name from patpat]]&gt;
      </queryString>
      <field class="java.lang.String" name="name"/>
      ...
      <text>&lt;![CDATA[name]]&gt;</text>
      ...
How can I preserve CDATA on the output..?
 
Old April 6th, 2007, 04:18 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Very odd. What XSLT transformation engine are you running and how are you invoking it?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 8th, 2007, 05:02 PM
Authorized User
 
Join Date: Apr 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm working on cocoon. Is it a problem that my CDATA where created with a rule similar to:

Code:
<queryString>
    <xsl:text disable-output-escaping="yes"><![CDATA[<![CDATA]]>[</xsl:text>
    <xsl:value-of select="child::info/child::document/child::sql:rowset/child::sql:row/child::sql:report_query"/>
    <xsl:text>]</xsl:text>
    <xsl:text disable-output-escaping="yes">]></xsl:text>
</queryString>
(couln't get cdata-section-elements to work)

 
Old April 8th, 2007, 05:11 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm not sure what you mean "is it a problem".

Using disable-output-escaping is always creating a problem in the sense that your code will work in some environments and not others, and will be less reusable. But it may solve your immediate problem.

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
escaping < char tclotworthy XSLT 16 September 21st, 2007 04:31 PM
Escaping quotes from content pblancher XSLT 1 June 18th, 2006 08:15 AM
Escaping Ampersand Entities android66 Visual Basic 2005 Basics 2 February 5th, 2005 04:46 AM
Escaping < and > barnaclebarnes XSLT 4 October 5th, 2004 08:56 AM
Removing Namespaces from XSL Transform output francislang XSLT 2 September 7th, 2004 07:58 AM





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