This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Re: Displaying document( ) output within 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]