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 Static HTML from database
I have a task to acomplish: I've got a bunch of FileMaker files (accessible through ODBC), and I need to generate a few Web pages from them. Some report items, N per page, with links to next/previous page.

I don't have the capability to run code on the Web server at the moment, so the pages need to be generated on the client and uploaded to the server. Is there a template system or something I can use, or do I have to resort to raw Perl (Python, Ruby - someting).
--

This guy's ahead of his time! He's using quantum programming methods: in universes where invalid data is passed to this function, it does not return. Thus you are ensured that you will only have valid data after calling it. Optimally you'd destroy the universe on failure, but computers haven't quite advanced to that level yet.

-- [link|http://thedailywtf.com/archive/2004/10/26/2920.aspx|The] Daily WTF

New Or VB.
/runs for cover.
bcnu,
Mikem

Eine Leute. Eine Welt. Ein F\ufffdhrer.
(Just trying to be accepted in the New America)
New Prebuilt template system just for you
output = ["<table>"]\nfor row in table:\n    output.append("<tr>")\n    for field in row:\n        output.append("<td>%s</td>" % field)\n    output.append("</tr>")\noutput.append("</table>")\nprint "\\n".join(output)\n


The Sig:
"Despite the seemingly endless necessity for doing
so, it's actually not possible to reverse-engineer intended invariants
from staring at thousands of lines of code (not in C, and not in
Python code either)."

Tim Peters on python-dev
New Come on.
This is exactly what I am trying to avoid. Quick and durty code writing simplistic HTML. Yes, I can write nested for loops. Thank you very much. Now, do we have any real ideas?
--

This guy's ahead of his time! He's using quantum programming methods: in universes where invalid data is passed to this function, it does not return. Thus you are ensured that you will only have valid data after calling it. Optimally you'd destroy the universe on failure, but computers haven't quite advanced to that level yet.

-- [link|http://thedailywtf.com/archive/2004/10/26/2920.aspx|The] Daily WTF

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..."
New How complex do you want to get?
There are templating systems for Perl, Python, and Java that will allow you to put the template in a separate file, then provide the template name and the data to put in it to the engine and have it produce the merged output. Most of them will have looping constructs in the template language, so you can provide, say, a list and have the template produce code for each iteration in the list.

If you're feeling lucky, you could even use Word's mail merge, I suppose. :-P
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New So, what would be a good one for Python?
I'll take Perl, too.

The idea is simple enough:

\n===================\n|                 |\n|    Logo         |\n|  Company Name   |\n|  Person Name    |\n|   Address       |\n|    Phone        | \n|     FAX         |\n===================\n


Company name may be a link in some cases. URL and logo file name come from DB.

Repeat the above for all record in query result, placing 15 record per page, generating links to next page, previous page, first, last.

It should also be flexible enough to allow fancier things if I have time later, e.g. generating alphabetical index.


--

This guy's ahead of his time! He's using quantum programming methods: in universes where invalid data is passed to this function, it does not return. Thus you are ensured that you will only have valid data after calling it. Optimally you'd destroy the universe on failure, but computers haven't quite advanced to that level yet.

-- [link|http://thedailywtf.com/archive/2004/10/26/2920.aspx|The] Daily WTF

New Sounds like a job for Perl's HTML::Template
I've never used it, but I know people who have[TM].
-YendorMike

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety."
- Benjamin Franklin, 1759 Historical Review of Pennsylvania
New There are a ton of good Perl template modules
Each tackling different kinds of problems. For a comparison, see [link|http://perl.apache.org/docs/tutorials/tmpl/comparison/comparison.html|http://perl.apache.o...n/comparison.html]. While the choices described there do not include templating tools in different languages, the article at least gives a framework to think about what you want from a templating tool, which helps you judge for other languages.

But you're right that HTML::Template aims to be very simple to get started with. That also means that it lacks features that other templating modules include.

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New That's the reason many people would choose Python
...there's no template because there doesn't need to be. If you spend 1 week learning the language, you can write what you need yourself in about an hour, AND the next such solution and the next one..., AND it'll be readable and usable in three years when the next guy comes along (even if that's you, again).
New That's going a bit far...
A good templating language can completely obviate the need for any programming at all in a simple job like this. Otherwise people wouldn't be writing generic templating systems for Python, and they definitely are. I've written one myself.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Meh. I'll meet that halfway
In my experience, most of the Python templating systems are just as hard to learn as writing your own in Python. Newbies often have a hard time discerning which few are not.
New So say it already
Which templating systems in Python are "the few that are not"? I am one of those newbies who have "hard time discerning".
--

This guy's ahead of his time! He's using quantum programming methods: in universes where invalid data is passed to this function, it does not return. Thus you are ensured that you will only have valid data after calling it. Optimally you'd destroy the universe on failure, but computers haven't quite advanced to that level yet.

-- [link|http://thedailywtf.com/archive/2004/10/26/2920.aspx|The] Daily WTF

New I can't think of any that do *everything* you want
The idea is simple enough:

===================
| |
| Logo |
| Company Name |
| Person Name |
| Address |
| Phone |
| FAX |
===================

Company name may be a link in some cases. URL and logo file name come from DB.

Repeat the above for all record in query result...


At this point pick whichever you like. Cheetah is probably best, given your simple page requirements. But there's no built-in database layer--you'll have to write that glue yourself using DBAPI or an odbc package.

...placing 15 record per page, generating links to next page, previous page, first, last.


I can't think of any that will do this part for you. So you'd have to write *some* code. Which leads us back to "might as well do it yourself". Soooo many projects like yours start with a templating engine, then hit the limitations of it, and roll their own anyway.
New *Sigh*
Then again, I get to code Python. Nothing to sigh about :)
--

It is illegitimate and utterly intolerant to impose such a view upon anyone, even upon yourselves.
-- [link|http://belmontclub.blogspot.com/|The Belmont Club]

New Me? :-)
Being serious, what about Apache's server-side includes? [link|http://httpd.apache.org/docs/howto/ssi.html|http://httpd.apache....cs/howto/ssi.html]

Wade.

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

New Can't rely on anything in th esrever beyond static pages.
--

This guy's ahead of his time! He's using quantum programming methods: in universes where invalid data is passed to this function, it does not return. Thus you are ensured that you will only have valid data after calling it. Optimally you'd destroy the universe on failure, but computers haven't quite advanced to that level yet.

-- [link|http://thedailywtf.com/archive/2004/10/26/2920.aspx|The] Daily WTF

     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)

I like working for this guy.
He calls himself my towel boy.
He knows how to motivate me.
84 ms