XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old July 19th, 2003, 12:51 PM
rum_beverage rum_beverage is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 rum_beverage User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
using html in a xsl formatted xml doc

i want to know how i can use an xsl file to format a xml file and keep all html code that it parses within xml tags. i want to be able to use the following xml document and have the xsl document (further down) output the desired html code....if i have to reformat the tags (ie. < -> <) etc. that is fine.

Code:
<?xml version="1.0"?>
   <newsPage>
      <news title="Test" date="Feb 20" posted="Ryan">
         This is just a test.
      </news>
      <news title="News Page" date="Feb 16" posted="Ryan">
         The news page is up and running.  Hopefully there will be more updates to come in the following days.
      </news>
      <news title="Blog" date="Feb 16" posted="Ryan">
         I've started writing to a blog.  If you have any interest at all you can read it <a href="http://www.dot.com">here</a>
      </news>
   </newsPage>


Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="/">
      <xsl:for-each select="newsPage">
         <table cellspacing="4">
            <xsl:for-each select="news">
               <tr>
                  <td class="newsTitle">
                     <xsl:value-of select="@title"/>
                  </td>
                  <td class="newsDate" align="right">
                     <xsl:value-of select="@date"/>
                  </td>
               </tr>
               <tr>
                  <td class="newsBody" colspan="2">
                     <xsl:value-of select="."/>
                  </td>
               </tr>
               <tr>
                  <td class="newsPosted" colspan="2" align="right">
                     posted by <xsl:value-of select="@posted"/>
                  </td>
               </tr>
            </xsl:for-each>
         </table>
      </xsl:for-each>
   </xsl:template>
</xsl:stylesheet>


as well i use the following javascript to publish

Code:
/*******************************************************************
********************************************************************
**                     Javascript for News Page                   **
********************************************************************
*******************************************************************/

function loadNewsXML() {
   var newsXML = new ActiveXObject("Microsoft.XMLDOM");
   newsXML.async = false;
   newsXML.load("xml/news.xml");
   return newsXML;
}

function loadNewsXSL() {
   var newsXSL = new ActiveXObject("Microsoft.XMLDOM");
   newsXSL.async = false;
   newsXSL.load("xsl/news.xsl");
   return newsXSL;
}

function loadNewsHTML() {
   var newsXML = loadNewsXML();
   //alert(newsXML);
   var newsXSL = loadNewsXSL();
   //alert(newsXSL);
   var newsHTML = newsXML.transformNode(newsXSL);
   //alert(newsHTML);
   news.innerHTML =  newsHTML;
}



if anybody could help me with this issue it would be appreciated

Last edited by rum_beverage : July 19th, 2003 at 12:56 PM.

Reply With Quote
  #2  
Old July 20th, 2003, 04:15 AM
DarrenJ DarrenJ is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 42 DarrenJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 21 sec
Reputation Power: 6
Html code needs to be placed inside a CDATA tag.

For example:
Code:
<?xml version="1.0"?>
   <newsPage>
      <news title="Test" date="Feb 20" posted="Ryan">
         This is just a test.
      </news>
      <news title="News Page" date="Feb 16" posted="Ryan">
         The news page is up and running.  Hopefully there will be more updates to come in the following days.
      </news>
<!-- here I have your code inside a cdata tag. -->
      <news title="Blog" date="Feb 16" posted="Ryan"><![CDATA[
         I've started writing to a blog.  If you have any interest at all you can read it <a href="http://www.dot.com">here</a>
      ]]></news>
   </newsPage>
__________________
Best regards
Darren

Reply With Quote
  #3  
Old July 20th, 2003, 08:22 AM
rum_beverage rum_beverage is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 rum_beverage User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
once i remembered i thought that would work but when i do it, it just shows the tag in the text that gets output

Reply With Quote
  #4  
Old July 30th, 2003, 01:22 AM
mulligh mulligh is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 19 mulligh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
1. Disable output-escaping

<td class="newsBody" colspan="2">
<xsl:value-of disable-output-escaping="yes" select="."/>
</td>

2. Replace < and > with < >
This will output the reference as is.

Reply With Quote
  #5  
Old August 5th, 2003, 09:17 AM
mitch22 mitch22 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 14 mitch22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
But if you use a variable "date" in your XSL like this:

code:--------------------------------------------------------------------------------<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="date" select="Feb 16"/>
<xsl:for-each select="newsPage">
<table cellspacing="4">
<xsl:for-each select="news">
<xsl:if test="@date>$date>
<tr>
<td class="newsTitle">
<xsl:value-of select="@title"/>
</td>
<td class="newsDate" align="right">
<xsl:value-of select="@date"/>
</td>
<td class="newsPosted" colspan="2" align="right">
posted by <xsl:value-of select="@posted"/>
</td>
</tr>
</xsl:if>

</xsl:for-each>
</table>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>--------------------------------------------------------------------------------


Now how are chnged the javascript functions to publish the code ?
Did anybody know ?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > using html in a xsl formatted xml doc


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway