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 August 13th, 2003, 08:38 AM
Registered User
 
Join Date: Jul 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default copy-of with disable-output-escaping?

Hello people!

I know that disable-output-escaping is not allowed on the copy-of element but how do I do to make a deep copy of a node with all its children including mark-up and transform it into another XML document?

I have my xml (containing xsl) for example:

<lokk-n-feel>
  <global>
    <xslt><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="foo">
        <xsl:value-of select="."/>
    </xsl:template>
</xsl:stylesheet>
    ]]></xslt>
  </global>

  <instance id="1">
    <xslt><![CDATA[
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="bar">
        <xsl:value-of select="."/>
    </xsl:template>
</xsl:stylesheet>
    ]]></xslt>
  </instance>
<lokk-n-feel>

How do I make a deep copy of <global> and all its children including the xsl unparsed? When I parse it (using Saxon 6.5.2 or MSXML 4.0), my stylesheet gets all messed up (as it says it would be in the XSLT spec.).

Thanks in advance
/Andrin
 
Old August 13th, 2003, 10:55 AM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

Hi!

I'm not sure if that's what you want, but check this out:

input XML
***********

<?xml version="1.0"?>
<lokk-n-feel>
    <global>
        <xslt><![CDATA[<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><xsl:apply-templates/></xsl:template><xsl:template match="foo"><xsl:value-of select="."/></xsl:template></xsl:stylesheet>]]></xslt>
    </global>
    <instance id="1">
        <xslt><![CDATA[<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><xsl:apply-templates/></xsl:template><xsl:template match="bar"><xsl:value-of select="."/></xsl:template></xsl:stylesheet>]]></xslt>
    </instance>
</lokk-n-feel>

XSLT
********

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" encoding="utf-8"/>
<xsl:template match="/">
    <xsl:apply-templates select="//global"/>
</xsl:template>
<xsl:template match="global">
    <xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

output
*************

<?xml version="1.0" encoding="utf-8"?>
<global>
    <xslt>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;&lt;xsl:template match="/"&gt;&lt;xsl:apply-templates/&gt;&lt;/xsl:template&gt;&lt;xsl:template match="foo"&gt;&lt;xsl:value-of select="."/&gt;&lt;/xsl:template&gt;&lt;/xsl:stylesheet&gt;</xslt>
</global>

Tell me if it's what you want. I hope it helped.

Luc

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
 
Old August 13th, 2003, 11:04 AM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

Hi! It's me again!

If you want to extract your XSLT from the output above, use the following stylesheet:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="xslt">
    <xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>

Have a nice day,

Luc

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
 
Old August 13th, 2003, 11:19 AM
Registered User
 
Join Date: Jul 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Luc

Thanks for you to answer me.

I want to get the XSL inside the CDATA unparsed. Now all < and > are replaced with &lt; and &gt;. This I don´t want. To be clear, I want this output:

<?xml version="1.0" encoding="utf-8"?>
<global>
  <xslt><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="foo">
    <xsl:value-of select="."/>
  </xsl:template>
</xsl:stylesheet>
  ]]></xslt>
</global>


But thanks anyway :-)
/Andrin
 
Old August 13th, 2003, 02:07 PM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

It's not really a deep copy, but still it does what you wanted.

******** XSLT ***************
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" encoding="utf-8"/>
    <xsl:template match="/">
        <xsl:apply-templates select="//global"/>
    </xsl:template>
    <xsl:template match="global">
        <xsl:copy>
            <xsl:apply-templates select="xslt"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="xslt">
        <xsl:copy>
            <xsl:apply-templates select="xslt"/>
            <xsl:variable name="xslContent">
                <xsl:copy-of select="."/>
            </xsl:variable>
            <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
            <xsl:value-of select="$xslContent" disable-output-escaping="yes"/>
            <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
 
Old July 16th, 2004, 04:46 AM
Registered User
 
Join Date: Jul 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This code seems to work on a task I'm working on as well. There I have a view element containing xml elements, that I want to go straight (copied) to the output while others are being processed and CDATA content copied to the output. Example:

<part type="text">
 <view>
   <h3>Welcome to this site Mr:
    <part type="math"><view>[CDATA[<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mrow>
    <msqrt>
      <mrow>
        <mi>&epsilon;</mi>
      </mrow>
    </msqrt>
  </mrow>
</math>
]]
    </view>
   </part>
  </h3>
 </view>
<part>


From that I would like to have:

<h3>Welcome to Mr.
 <math xmlns="http://www.w3.org/1998/Math/MathML">
  <mrow>
    <msqrt>
      <mrow>
        <mi>#949;</mi>
      </mrow>
    </msqrt>
  </mrow>
 </math>
</h3>

I'm almost there. The only thing I'm missing is the <h3></h3> tags. How can I get that to the output?

To be more precise I would like to copy the entire view part after extracting the CDATA-section. My idea is to make a copy-of a variable containing the view with the extracted CDATA.

Any ideas or suggestion?

Thanks

Morten Andersen






Similar Threads
Thread Thread Starter Forum Replies Last Post
<?javax.xml.transform.disable-output-escaping ?> robbert XSLT 5 January 5th, 2011 07:28 PM
Disable Copy Paste sridevi HTML Code Clinic 5 August 11th, 2007 05:09 AM
Finding an alternative to disable-output-escaping nickbond XSLT 4 November 15th, 2006 05:28 PM
Copy source-element to output tree der_bAUer XSLT 2 June 9th, 2006 08:17 AM
Disable-Output-Escaping in .NET Transform tclancy XSLT 3 March 1st, 2006 09:27 AM





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