[xsl] Re: Re: Displaying document( ) output within CDATA

Subject: [xsl] Re: Re: Displaying document( ) output within CDATA
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Thu, 28 Jun 2001 04:39:51 -0700 (PDT)
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?"


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:
   <codeReference href="identity.xsl"/>

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


    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:apply-templates select="@*|node()"/>
<div id="divIDA5EXLB"></div>

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:APPLY-TEMPLATES select="@*|node()" />

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.


Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail

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

Current Thread