[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re: Displaying document( ) output within CDATA

Subject: Re: Re: Displaying document( ) output within CDATA
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Thu, 28 Jun 2001 04:39:51 -0700 (PDT)
xsl display cdata
Mark Miller wrote:

> You are correct that I should be using 'copy-of'
> instead of 'value-of' to get a copy of the desired
> document. However, this does not solve the original
> problem.
> 
> I want to display the literal code on the page, not
> the results of the code. I am able to do this by
> cutting and pasting the code into a CDATA section, but
> I'd prefer to do it by generating the example code
> dynamically from an external file.
> 
> Rephrasing the question, "How can I output literal
> code, not the results of the code, into HTML when the
> code is stored in an eternal file?"

Mark,

You do not get "the results of the code" -- just the code.

Here's a solution to your problem (not decorated with headings etc...):

xml source:
----------
<examples>
  <example>
   <codeReference href="identity.xsl"/>
  </example>
</examples>

stylesheet:
----------
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
  <html>
   <script>
    function init()
    {
     <xsl:for-each select="examples/example">
       <xsl:value-of select="concat('div',generate-id())"/>.innerText =
<xsl:value-of select="generate-id()"/>.innerHTML
     </xsl:for-each>
    }
   </script>
   <body onload="init()">
    <xsl:apply-templates/>
   </body>
 </html>
 </xsl:template>
 <xsl:template match="example">
  <pre id="{generate-id(.)}">
    <xsl:apply-templates/>
  </pre>
  <div id="{concat('div',generate-id())}"></div>
 </xsl:template>
 <xsl:template match="codeReference">
   <xsl:copy-of select="document(@href)"/>
 </xsl:template>

</xsl:stylesheet>

Result:
------
<html><script>
    function init()
    {
     divIDA5EXLB.innerText = IDA5EXLB.innerHTML
     
    }
   </script><body onload="init()">
<pre id="IDA5EXLB">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</pre>
<div id="divIDA5EXLB"></div>
</body>
</html>


IE displays:
-----------
<XSL:STYLESHEET xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<XSL:OUTPUT indent="yes" method="xml" />
<XSL:TEMPLATE match="@*|node()">
<XSL:COPY>
<XSL:APPLY-TEMPLATES select="@*|node()" />
</XSL:COPY>
</XSL:TEMPLATE>
</XSL:STYLESHEET>


This is only for illustration of the idea -- some things have still to be worked out
(e.g. the capitalisation), but the idea should be clear.

Cheers,
Dimitre.


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.