xslt queries in xml to SQL queries

Crutcher crutcher at gmail.com
Sun Feb 26 00:18:18 EST 2006


Skipping ahead, let me try to rephrase this.

First, this isn't really a python question, it is SQL, XSLT, and
program design, but I'll try to answer.

You have templates, they contain general layout stuff, and input
fields. You are transforming them into HTML pages, and part of what you
want to do is to expand the enumerated fields with the enumeration
values at the time of template application.

You read an article about XSLT, and decided that you could use it in
your app. For some unknown reason, perhaps involving large amounts of
alcohol, you want to use the syntax of XSLT, but have it actually
parsed by python, which silently does an SQL querry to give you your
results.

This is a really, really bad idea. There are many ways to solve your
problem using XSLT, and though all of them are easy, none of them are
so simple that I could put them in a post to someone who doesn't know
XSLT. If you know XSLT, follow the directions below, if you don't, DO
NOT USE XSLT for this project. And for the love of anything you may
believe in, don't try to implement a partial XSLT engine in python.


Pattern 1, paramaterized templates:

Pattern 1 assumes that all the data you will need for your templates is
known in advance, and is common to your templates. If this is true, you
need only generate an XML fragment with the data you need, and compose
a document which contains both the data you need, and the page template
you are rendering. Then, write an XSLT transform to build your pages,
which can now resolve data needs in the template section using the data
provided in the data section.

Pattern 2, query extraction:

When you don't know what data the page template might need, and the
full dataset is unmanageably large, you can't use pattern 1 easily. So
instead, write an XSLT transform which _only_ extracts information
about the data you need. You can then run this transform, get the query
list, perform the queries, and use the resultant data for the data tree
from pattern 1.




More information about the Python-list mailing list