IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New XSLT?
Here's an XML stylesheet (festoon taggery to taste):

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="[link|http://www.w3.org/1999/XSL/Transform|http://www.w3.org/1999/XSL/Transform]"><xsl:template match="/">
<html>
<body>
<table>
<xsl:for-each select="recordset/record">
<tr>
<td><xsl:value-of select="field1" /></td>
<td><xsl:value-of select="field2" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

But you'll need to feed it an XML document. Generate one thusly (thanks FuManChu)(4 lines in for-loop should of course be indented):

output = ['<?xml version="1.0" encoding="ISO-8859-1"?>']
output.append("<recordset>")
for record in recordset:
output.append("<record>")
output.append("<field1>%s</field1>" % field1)
output.append("<field2>%s</field2>" % field2)
output.append("</record>")
output.append("</recordset>")
print "\\n".join(output)


For bonus IE-only points, you can apply the stylesheet at runtime with this:


<html>
<body><script type="text/javascript">// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("recordset.xml")
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("stylesheet.xsl")
document.write(xml.transformNode(xsl))</script>
</body>
</html>


;)
--
Chris Altmann
Expand Edited by altmann Dec. 8, 2004, 04:20:07 PM EST
New UGH! He's better off with plain ol C code.
At least you can read it.



"The significant problems we face cannot be solved at the same level of thinking we were at when we created them."     --Albert Einstein

"This is still a dangerous world. It's a world of madmen and uncertainty and potential mental losses."     --George W. Bush
Expand Edited by tuberculosis Aug. 21, 2007, 06:35:25 AM EDT
New Sorry
Sorry, I had to turn off HTML processing for that post because it was mangling the xsl. Or was that what you meant?

Also, to insure well-formed XML, I probably should have written that middle snippet like so (in VB.Net this time):
\nDim writer As New XmlTextWriter(outputStream)\n\nwriter.Formatting = Formatting.Indented\n\nwriter.WriteStartElement("recordset")\n\nForeach record in recordset\n   writer.WriteStartElement("record")\n   writer.WriteElementString("field1", XmlConvert.ToString(field1))\n   writer.WriteElementString("field2", XmlConvert.ToString(field2))\n   writer.writeEndElement()\nNext\n\nwriter.WriteEndElement()\nwriter.Close()\n


Much cleaner.

8)
--
Chris Altmann
New XSL isn't bad for simple, quick and dirty formatting
I wouldn't use it for anything remotely complex, though.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
     Static HTML from database - (Arkadiy) - (19)
         Or VB. - (mmoffitt)
         Prebuilt template system just for you - (FuManChu) - (15)
             Come on. - (Arkadiy) - (14)
                 XSLT? - (altmann) - (3)
                     UGH! He's better off with plain ol C code. - (tuberculosis) - (2)
                         Sorry - (altmann)
                         XSL isn't bad for simple, quick and dirty formatting - (admin)
                 How complex do you want to get? - (admin) - (9)
                     So, what would be a good one for Python? - (Arkadiy) - (8)
                         Sounds like a job for Perl's HTML::Template - (Yendor) - (1)
                             There are a ton of good Perl template modules - (ben_tilly)
                         That's the reason many people would choose Python - (FuManChu) - (5)
                             That's going a bit far... - (admin) - (4)
                                 Meh. I'll meet that halfway - (FuManChu) - (3)
                                     So say it already - (Arkadiy) - (2)
                                         I can't think of any that do *everything* you want - (FuManChu) - (1)
                                             *Sigh* - (Arkadiy)
         Me? :-) - (static) - (1)
             Can't rely on anything in th esrever beyond static pages. -NT - (Arkadiy)

Welcome to those that can stand it.
82 ms