|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
once i remembered i thought that would work but when i do it, it just shows the tag in the text that gets output
|
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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 ? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > using html in a xsl formatted xml doc |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|