Solved

XSL and CDATA Help???

Posted on 2004-04-06
10
710 Views
Last Modified: 2008-03-06
I am trying to include a menu.htm file into the xsl file.

I include in the xsl file where i need the menu.htm to show up.
<![CDATA[
<!-- The html is goes here -->
]]>

But for some reason when i load the xsl file, it shows up the html that i inserted between  the CDATA's tags is shown here. I noticed one thing when i viewed the View Source. The page has converted < to &lt; etc. A sample of the javascript code which i use in the CDATA is shown as follows:


&lt;script language="javascript"&gt;
function swapIt(hide, show) {
  hide.style.display = "none";
  show.style.display = "";
  }
&lt;/script&gt;

Is there any setting that i am missing.

Thanks
0
Comment
Question by:CIT_DEV
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 12

Expert Comment

by:dfiala13
ID: 10769470
put the CDATA inside <xsl:text disable-out-escaping="yes"> </xsl:text>
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 10769493
try this approach:

<xsl:text disable-output-escaping="yes">
<![CDATA[
   <script language="javascript">
      function swapIt(hide, show) {
              hide.style.display = "none";
              show.style.display = "";
        }
    </script>
]]>
</xsl:text>

Hope it helps you .
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 10769498
This is how I do it:

<script language="javascript"><![CDATA[
function swapIt(hide, show) {
  hide.style.display = "none";
  show.style.display = "";
  }
]]></script>


If you need to insert values from the transformation into the script code, you have to "open a hole" in the CDATA:

<script language="javascript"><![CDATA[
function swapIt(hide, show) {
  var myString = "]]><xsl:value-of select="path/to/data"/><![CDATA[";
  hide.style.display = "none";
  show.style.display = "";
  }
]]></script>

If this doesn't answer your question, post more of the XSLT as it is coded, so I can see what you're trying to do.

Regards,
Mike Sharp
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 10769501
whee...i'm only second ;)
0
 
LVL 1

Author Comment

by:CIT_DEV
ID: 10769650
ArchiveMenu.htm


<script language="javascript">
function swapIt(hide, show) {
  hide.style.display = "none";
  show.style.display = "";
  }
</script>
<link rel="stylesheet" href="full.css">
<script language="JavaScript" src="includes/Common.js" type="text/javascript"></script>
<table border="0" cellspacing="0" cellpadding="0" width="175">
  <tr>
    <td valign="top"><IMG height=1 src="images/spacers.gif" width=175><br>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="14" background="images/gadget-header_bg.gif"><IMG height=18 src="images/gadget-header_corner.gif"

width=14></td>
         
          <td bgcolor="#9cbece" align="right" nowrap valign="bottom" background="images/gadget-header_bg2.gif">&nbsp;</td>
          <td background="images/gadget-header_bg.gif" align="right" valign="top"><IMG height=18 src="images/right-edge.gif"

width=1></td>
        </tr>
      </table>
     <!--2004 -->
      <table border="0" cellspacing="0" cellpadding="0" width="175" class="greyborder">
 
        <tr>
            
          <td id=onetable style="DISPLAY: none" align="left"
          valign="top">
            <table border="0" cellspacing="0" cellpadding="2" width="100%">
              <tr>
                <td class="newsboxheader" align="left" valign="top" colspan="2"><b><IMG style="CURSOR: hand"

onclick=swapIt(onetop,onetable) height=5 alt=More src="images/spacers.gif" width=5 ></b><span

class="gadgetheaderwhite"><b><IMG style="CURSOR: hand" onclick=swapIt(onetop,onetable) height=1 alt=More

src="images/spacers.gif" width=140 ></b><br>
                  </span><span class="orangetxt"><b>2004</b></span></td>
                <td class="newsboxheader" valign="top" align="right"><b><IMG style="CURSOR: hand"

onclick=swapIt(onetable,onetop) height=15 alt=Less src="images/buttonarrow_up-b.gif" width=19 ></b></td>
              </tr>


                        <!--PRINT THE VALUES FOR EACH MONTH -->
                        <tr align="left" valign="top">
                              <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=01">January</A></td>
                </tr>
                <tr align="left" valign="top">
                              <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=02">February</A></td>
                </tr>
                <tr align="left" valign="top">
                              <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=03">March</A></td>
                </tr>
                <tr align="left" valign="top">
                              <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=04">April</A></td>
                </tr>
                <tr align="left" valign="top">
                              <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=05">May</A></td>
                </tr>
                <tr align="left" valign="top">
                              <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=06">June</A></td>
                </tr>
                <tr align="left" valign="top">
                              <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=07">July</A></td>
                </tr>
                <tr align="left" valign="top">
                              <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=08">August</A></td>
                </tr>
                <tr align="left" valign="top">
                              <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=09">September</A></td>
                </tr>
                <tr align="left" valign="top">
                              <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=10">October</A></td>
                </tr>
                <tr align="left" valign="top">
                              <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=11">November</A></td>
                </tr>
                <tr align="left" valign="top">
                              <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=12">December</A></td>
                </tr>
            </table>
      </table>
     <!--2003 -->
   
     <!--2002 -->
     
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>

*******************************************
XSL FILE
*******************************************

<?xml version="1.0" encoding="UTF-8"  ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                                         xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                                                          xmlns:date="http://www.test.com/corporate-it"
                                                          extension-element-prefixes="date"
                                                          exclude-result-prefixes="date msxsl">

      <xsl:import href="../../common/_xsl/date_library.xslt"/>
                                                        
      <xsl:output method="html" version="1.0" indent="yes" encoding="UTF-8" />


      <xsl:template match="root">
<html>
      <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title>ITMT Questions &amp; Answers</title>
            <script language="javascript">                        
                        function showHideAnswer(strID) {
                              document.all(strID).style.display = (document.all(strID).style.display == "none") ? "inline" : "none"
                              window.event.srcElement.innerText = (document.all(strID).style.display == "none") ? "Show Answer" : "Hide Answer"
                              return false
                        }      
                  function printPage() {
                    if (window.print)
                      window.print()
                    else
                      alert("Sorry, your browser doesn't support this feature.");
                  }
            </script>      
            <link rel="stylesheet" href="styles.css" type="text/css"/>
            
      </head>

      <body link="blue" alink="blue" vlink="blue" topmargin="0" leftmargin="0">
<table width="185" height="100%" cellpadding="0" cellspacing="0" border="0">
                        <tr>
                              <td width="175" height="100%">
                                    <table bgcolor="FFF8DE" width="175" height="550" cellpadding="0" cellspacing="0" border="0">
                                          <tr>
                                                <td colspan="2" width="175" height="23" valign="top"><img src="images/spacer.gif" width="175" height="23" alt="" border="0"/></td>
                                          </tr>
                                          <tr>
                                                <td width="5%" align="left" valign="top" height="100%"></td>
                                                <td valign="top">      
                                                      <table id="tblHomePageNavigation" cellpadding="2" border="0" width="100%" cellspacing="0">
                                                            <tr>
                                                                  <td>
                                                                  <!--START OF THE ARCHIVE MENU LIST -->
                                                                  
                                                                                                                                    
                                                                        <![CDATA[
                                                                  
                                                                        ]]>

                                                                  <!--END OF THE ARCHIVE LIST -->
                                                                  </td>
                                                            </tr>
                                                            <tr>
                                                                  <td><a href="question_sub.asp?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 12

Expert Comment

by:dfiala13
ID: 10771890
<!--START OF THE ARCHIVE MENU LIST -->
<xsl:text disable-out-escaping="yes"> <![CDATA[  


HTML here



 ]]>
</xsl:text>
<!--END OF THE ARCHIVE LIST -->

Of course, I think I'd just leave the html in a separate file and use an include there instead.

 <!--START OF THE ARCHIVE MENU LIST -->
<!-- #include virtual="/ArchiveMenu.htm" -->

<!--END OF THE ARCHIVE LIST -->
0
 
LVL 1

Author Comment

by:CIT_DEV
ID: 10772028
The include solution fails.
<!-- #include virtual="/ArchiveMenu.htm" -->

The Embedded html between the <![CDATA[  ]]> also fails. The information between the CDATA is being transformed with special characters (ie < get converted to &lt;  etc) even after escaping is diabled.


0
 
LVL 15

Accepted Solution

by:
dualsoul earned 250 total points
ID: 10772415
CIT_DEV

this:
.................................................................................
<xsl:text disable-output-escaping="yes">
<![CDATA[
<script language="javascript">
function swapIt(hide, show) {
  hide.style.display = "none";
  show.style.display = "";
  }
</script>
<link rel="stylesheet" href="full.css">
<script language="JavaScript" src="includes/Common.js" type="text/javascript"></script>
<table border="0" cellspacing="0" cellpadding="0" width="175">
  <tr>
    <td valign="top"><IMG height=1 src="images/spacers.gif" width=175><br>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="14" background="images/gadget-header_bg.gif"><IMG height=18 src="images/gadget-header_corner.gif"

width=14></td>
         
          <td bgcolor="#9cbece" align="right" nowrap valign="bottom" background="images/gadget-header_bg2.gif">&nbsp;</td>
          <td background="images/gadget-header_bg.gif" align="right" valign="top"><IMG height=18 src="images/right-edge.gif"

width=1></td>
        </tr>
      </table>
     <!--2004 -->
      <table border="0" cellspacing="0" cellpadding="0" width="175" class="greyborder">
 
        <tr>
         
          <td id=onetable style="DISPLAY: none" align="left"
          valign="top">
            <table border="0" cellspacing="0" cellpadding="2" width="100%">
              <tr>
                <td class="newsboxheader" align="left" valign="top" colspan="2"><b><IMG style="CURSOR: hand"

onclick=swapIt(onetop,onetable) height=5 alt=More src="images/spacers.gif" width=5 ></b><span

class="gadgetheaderwhite"><b><IMG style="CURSOR: hand" onclick=swapIt(onetop,onetable) height=1 alt=More

src="images/spacers.gif" width=140 ></b><br>
                  </span><span class="orangetxt"><b>2004</b></span></td>
                <td class="newsboxheader" valign="top" align="right"><b><IMG style="CURSOR: hand"

onclick=swapIt(onetable,onetop) height=15 alt=Less src="images/buttonarrow_up-b.gif" width=19 ></b></td>
              </tr>


                    <!--PRINT THE VALUES FOR EACH MONTH -->
                    <tr align="left" valign="top">
                         <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=01">January</A></td>
                </tr>
                <tr align="left" valign="top">
                         <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=02">February</A></td>
                </tr>
                <tr align="left" valign="top">
                         <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=03">March</A></td>
                </tr>
                <tr align="left" valign="top">
                         <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=04">April</A></td>
                </tr>
                <tr align="left" valign="top">
                         <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=05">May</A></td>
                </tr>
                <tr align="left" valign="top">
                         <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=06">June</A></td>
                </tr>
                <tr align="left" valign="top">
                         <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=07">July</A></td>
                </tr>
                <tr align="left" valign="top">
                         <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=08">August</A></td>
                </tr>
                <tr align="left" valign="top">
                         <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=09">September</A></td>
                </tr>
                <tr align="left" valign="top">
                         <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=10">October</A></td>
                </tr>
                <tr align="left" valign="top">
                         <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=11">November</A></td>
                </tr>
                <tr align="left" valign="top">
                         <td class="newsboxyellow" colspan="2"><CENTER><A class=smalltext

href="questionsMonth.asp?yy=04&mm=12">December</A></td>
                </tr>
           </table>
      </table>
     <!--2003 -->
   
     <!--2002 -->
     
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
                                                       
]]>
</xsl:text>
.................................................................................

outputs all inside CDATA section as is. No any replacement of < to &lt; and so on.
if it still doesn't work, please post full XSLT you are trying to make work, so we can check it.
0
 
LVL 1

Author Comment

by:CIT_DEV
ID: 10775010
I am getting an error if i use <xsl:text disable-output-escaping="yes">. The XML is not well formated. If i change this to <xsl:text disable-output-escaping="yes"/> then the xml is well formated,
Should i be using <xsl:text disable-output-escaping="yes"/>
0
 
LVL 1

Author Comment

by:CIT_DEV
ID: 10775083
I used
<xsl:text disable-output-escaping="yes">
<![CDATA[

INSERT TEXT HERE
 ]]></xsl:text>

I finally got it to work. I forgot the end tag "</xsl:text> "


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now