I don't know PHP but your script gives the impression that the stylesheet is
writing the result tree to a tree in memory, not serializing it to a stream.
The serialization of the tree is being done later, presumably by some PHP
code that is quite unaware of what the stylesheet said in its xsl:output.
xsl:output properties only take effect when the XSLT processor performs the
serialization.
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: adam(_at_)twosmith(_dot_)plus(_dot_)com
[mailto:adam(_at_)twosmith(_dot_)plus(_dot_)com]
Sent: 10 October 2007 09:43
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] XSLT HTML Formatted output
Can anyone tell me why I cant get the output from my XSLT
test to output with the HTML indented?
I have tried the indent option but the html still comes out
with all the intents stripped out.
I am a complete newbe with all of this, I am trying to make
the swich from Smarty template engine to XSLT.
Here is what i am doing.
Firstly I have a php script that pulls the XML file and XSL
files together:
---
<?php
$xsl_filename = "styles.xsl";
$xml_filename = "data.xml";
$doc = new DOMDocument();
$xsl = new XSLTProcessor();
$doc->load($xsl_filename);
$xsl->importStyleSheet($doc);
$doc->load($xml_filename);
echo $xsl->transformToXML($doc);
?>
---
This is my XML test data:
---
<?xml version="1.0" encoding="ISO-8859-1"?> <root>
<title>Welcome to this site</title>
<catalog>
<cd>
<id>1</id>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.9000</price>
<year>1985</year>
</cd>
<cd>
<id>2</id>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.9000</price>
<year>1988</year>
</cd>
<cd>
<id>3</id>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.9000</price>
<year>1982</year>
</cd>
<cd>
<id>4</id>
<title>Still got the blues</title>
<artist>Gary Moore</artist>
<country>UK</country>
<company>Virgin records</company>
<price>10.2000</price>
<year>1990</year>
</cd>
<cd>
<id>5</id>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.9000</price>
<year>1997</year>
</cd>
<cd>
<id>6</id>
<title>One night only</title>
<artist>Bee Gees</artist>
<country>UK</country>
<company>Polydor</company>
<price>10.9000</price>
<year>1998</year>
</cd>
<cd>
<id>7</id>
<title>Sylvias Mother</title>
<artist>Dr.Hook</artist>
<country>UK</country>
<company>CBS</company>
<price>8.1000</price>
<year>1973</year>
</cd>
<cd>
<id>8</id>
<title>Maggie May</title>
<artist>Rod Stewart</artist>
<country>UK</country>
<company>Pickwick</company>
<price>8.5000</price>
<year>1990</year>
</cd>
<cd>
<id>9</id>
<title>Romanza</title>
<artist>Andrea Bocelli</artist>
<country>EU</country>
<company>Polydor</company>
<price>10.8000</price>
<year>1996</year>
</cd>
<cd>
<id>10</id>
<title>When a man loves a woman</title>
<artist>Percy Sledge</artist>
<country>USA</country>
<company>Atlantic</company>
<price>8.7000</price>
<year>1987</year>
</cd>
<cd>
<id>11</id>
<title>Black angel</title>
<artist>Savage Rose</artist>
<country>EU</country>
<company>Mega</company>
<price>10.9000</price>
<year>1995</year>
</cd>
<cd>
<id>12</id>
<title>1999 Grammy Nominees</title>
<artist>Many</artist>
<country>USA</country>
<company>Grammy</company>
<price>10.2000</price>
<year>1999</year>
</cd>
<cd>
<id>13</id>
<title>For the good times</title>
<artist>Kenny Rogers</artist>
<country>UK</country>
<company>Mucik Master</company>
<price>8.7000</price>
<year>1995</year>
</cd>
<cd>
<id>14</id>
<title>Big Willie style</title>
<artist>Will Smith</artist>
<country>USA</country>
<company>Columbia</company>
<price>9.9000</price>
<year>1997</year>
</cd>
<cd>
<id>15</id>
<title>Tupelo Honey</title>
<artist>Van Morrison</artist>
<country>UK</country>
<company>Polydor</company>
<price>8.2000</price>
<year>1971</year>
</cd>
<cd>
<id>16</id>
<title>Soulsville</title>
<artist>Jorn Hoel</artist>
<country>Norway</country>
<company>WEA</company>
<price>7.9000</price>
<year>1996</year>
</cd>
</catalog>
</root>
---
This is my XSL data:
---
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="/root">
<html>
<head>
<title><xsl:apply-templates
select="title"/></title>
</head>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<xsl:sort select="price" />
<tr>
<td><xsl:value-of
select="title"
/></td>
<xsl:choose>
<xsl:when test="price > 10">
<td
bgcolor="#ff00ff"><xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:when test="price > 9">
<td
bgcolor="#cccccc"><xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of
select="artist"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="title">:: <xsl:value-of select="."/>
::</xsl:template>
</xsl:stylesheet>
---
And this is the source of the result (not indented??):
---
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>:: Welcome to this site ::</title> </head> <body>
<h2>My CD Collection</h2> <table border="1"> <tr
bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <tr>
<td>Still got the blues</td> <td bgcolor="#ff00ff">Gary
Moore</td> </tr> <tr>
<td>1999 Grammy Nominees</td>
<td bgcolor="#ff00ff">Many</td>
</tr>
<tr>
<td>Romanza</td>
<td bgcolor="#ff00ff">Andrea Bocelli</td> </tr> <tr>
<td>Empire Burlesque</td> <td bgcolor="#ff00ff">Bob
Dylan</td> </tr> <tr> <td>One night only</td> <td
bgcolor="#ff00ff">Bee Gees</td> </tr> <tr> <td>Black
angel</td> <td bgcolor="#ff00ff">Savage Rose</td> </tr> <tr>
<td>Soulsville</td> <td>Jorn Hoel</td> </tr> <tr> <td>Sylvias
Mother</td> <td>Dr.Hook</td> </tr> <tr> <td>Tupelo Honey</td>
<td>Van Morrison</td> </tr> <tr> <td>Maggie May</td> <td>Rod
Stewart</td> </tr> <tr> <td>When a man loves a woman</td>
<td>Percy Sledge</td> </tr> <tr> <td>For the good times</td>
<td>Kenny Rogers</td> </tr> <tr> <td>Hide your heart</td> <td
bgcolor="#cccccc">Bonnie Tyler</td> </tr> <tr> <td>Greatest
Hits</td> <td bgcolor="#cccccc">Dolly Parton</td> </tr> <tr>
<td>Eros</td> <td bgcolor="#cccccc">Eros Ramazzotti</td>
</tr> <tr> <td>Big Willie style</td> <td
bgcolor="#cccccc">Will Smith</td> </tr> </table> </body> </html>
---
Can anyone see if i am doing something wrong?
Cheers,
Adam
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--