| 06-04-2008, 04:32 PM | #1 |
I'm making an XML application and the code looks like this XML File Code:
<?xml version="1.0" encoding="utf-8" ?> <?xml-stylesheet type="text/xsl" href="newsfeed.xsl"?> <feed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="newsfeed.xsd"> <item> <title>Test</title> <date>6/4/08</date> <category>Tests</category> <author>TSA</author> <body>This is a test of my XML feed application</body> </item> <item> <title>Test 2</title> <date>6/4/08</date> <category>Tests</category> <author>TSA</author> <body>This is a test of multiple items</body> </item> <item> <title>Test 4</title> <date>6/5/08</date> <category>Tests</category> <author>TSA</author> <body>This is another date-sort test for multiple items</body> </item> <item> <title>Test 3</title> <date>6/3/08</date> <category>Tests</category> <author>TSA</author> <body>This is a date-sort test for multiple items</body> </item> <item> <title>Test 6</title> <date>6/10/08</date> <category>Tests</category> <author>TSA</author> <body>This is a long text test.<br />It is also an integrated HTML code test. It tests integrity over a large amount of <b>characters</b> and several forms of <a href="">HTML</a> code. Test failed. How to fix? Requires XSLT to solve... Large Text Block Test: Passed<br />HTML Element Test: Failed<br />Date Sort: Passed<br />App Test: Passed</body> </item> </feed> XSL File Code:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>News Feed</title>
<style type="text/css">
body{font-size:"16px";background-color:"#CCCCCC"}
#title{font-size:"20px";font-weight:"bold"}
#date{font-size:"12px"}
#category{font-size:"12px"}
#author{font-size:"12px"}
#footer{font-size:"12px";text-align="center"}
#sorttitle{font-size:"16px";font-weight:"bold"}
hr#divider{color:"#33AACC";height:"16px"}
</style>
</head>
<body>
<table width="100%" align="top">
<tr>
<td width="85%">
<xsl:for-each select="feed/item">
<xsl:sort select="date" order="descending" /><div name="sortmethod"></div>
<hr id="divider" />
<div id="title"><xsl:value-of select="title" /></div>
<div id="date"><xsl:value-of select="date" /></div>
<div id="category"><xsl:value-of select="category" /></div>
<div id="author"><xsl:value-of select="author" /></div>
<div id="body"><xsl:value-of select="body" /></div>
</xsl:for-each>
<hr id="divider" />
</td><td align="right" valign="top"><div id="title">XML News Feed</div><br /><br /><div id="sorttitle">Sort by:</div>Date<br />Title<br />Category (Ascending)<br />Category (Descending)</td></tr></table>
<hr />
<div id="footer">This XML News Feed Application is built by TSA</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>XSD File(Schema) Code:
<?xml version="1.0" encoding="utf-8" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- simple elements --> <xs:element name="title" type="xs:string" /> <xs:element name="date" type="xs:date" /> <xs:element name="category" type="xs:string" /> <xs:element name="author" type="xs:string" /> <xs:element name="body" type="xs:string" /> <!-- complex elements --> <xs:element name="feed"> <xs:complexType> <xs:sequence> <xs:element name="item"> <xs:complexType> <xs:sequence> <xs:element ref="title" /> <xs:element ref="date" /> <xs:element ref="category" /> <xs:element ref="author" /> <xs:element ref="body" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> The problem? I don't know how to get HTML Data contained in the XML <body> tags to be parsed as HTML. IE. The <br />s cause linebreaks. |
| 06-04-2008, 08:46 PM | #2 |
parsed by what? |
| 06-04-2008, 10:20 PM | #3 | ||
okay, let me explain. Code:
<body>This is a long text test.<br />It is also an integrated HTML code test. It tests integrity over a large amount of <b>characters</b> and several forms of <a href="">HTML</a> code. Test failed. How to fix? Requires XSLT to solve... Large Text Block Test: Passed<br />HTML Element Test: Failed<br />Date Sort: Passed<br />App Test: Passed</body> Quote:
Quote:
I think I might have a solution. Make the body contain many sub elements (IE; PureString, BoldText, LinkText, Image, etc.) that get interpreted by the XSL file. |
| 06-05-2008, 07:48 PM | #4 |
You have to declare an xhtml doctype for the output. Preferably within a namespace, but that's up to you. Like this: PHP Code:
(and yes, I do like my xhtml strict and valid) |
| 06-06-2008, 01:06 AM | #5 |
Thanks, but your solution killed all of my CSS. And HTML code in the XML file is still not maintained. and you don't have the XML declaration at the start of yours PHP Code:
this is my new XSL file PHP Code:
|
| 06-06-2008, 03:30 PM | #6 |
Oooooh, I get it, you had xhtml markup within your xml file. I don't recall off hand if you can have xhtml tags outside an <html> tag, but you could try declaring an html namespace for all such elements you need, so the xsl stylesheet knows that those tags do not belong to the newsfeed schema and tries to keep them. Either that, of you will have to transform each manually. EDIT: Possible help: http://developers.slashdot.org/devel....shtml?tid=156 Also, "inline" info from another language/format within html should be always in a <![CDATA[ ... ]]> tag to prevent interpreters go retarded. It also makes the w3c xml/html validator act nice to you. And sorry about my xsl stylesheet. I wrote it on a rush. EDIT: A dirty hack I forgot about would be the disable-output-escaping parameter on the value-of tag: I would try to avoid it nevertheless. http://www.dpawson.co.uk/xsl/sect2/N2215.html |
