PDA

View Full Version : Formatting Text - using XML



AceTutor
01 Jun 2006, 08:43 AM
Greetings Folks

Here is my first challenge with code following:
Can I add tags to "text" in my .xml file so that I can have bold, italic, underline and link info embedded when using an .xsl stylesheet to format same?


Here is my sample .xml file called "demo.xml":


<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="demo.xsl" type="text/xsl"?>
<demo>
<text>
<start>The quick brown fox</start>
<finish>jumps over the lazy dog</finish>
</text>
</demo>




And here is my .xsl file called "demo.xsl":


<?xml version="1.0" encoding="iso-8859-1"?><!-- DWXMLSource="demo.xml" --><!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
<!ENTITY copy "">
<!ENTITY reg "">
<!ENTITY trade "">
<!ENTITY mdash "">
<!ENTITY ldquo "">
<!ENTITY rdquo "">
<!ENTITY pound "">
<!ENTITY yen "">
<!ENTITY euro "">
]>
<xsl:stylesheet version="1.0" xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="<A href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Untitled Document</title>
</head>
<body><table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="right"><xsl:value-of select="demo/text/start"/></div></td>
<td>&nbsp;<xsl:value-of select="demo/text/finish"/></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


By asking IE or Firefox to display demo.xml I get the following result:


The quick brown fox jumps over the lazy dog.


Challenge: Can I have it rendered like this -

The quick brown fox jumps over the lazy dog (http://www.google.com).

If lazy dog can be made a hyperlink as well then I would say XML really "ROCKS".


The 2nd challenge is:
Can I have a lengthy passage of text and be able to assign paragraph breaks so the browser will display sentences in paragraphs?
(I trust this does not need an example and my request is self explanitory)


If you can help me, with say a working example, I would be so appreciative.

Thanks in anticipation


AceTutor


PS. Above code all generated using Dreamweaver 8

cdwhalley.com
01 Jun 2006, 11:38 AM
I've never dabbled with XML too much.
Look on www.w3schools.com for some help?