Hello,
I want to embed SQL type queries within an XML data record. The XML
looks something like this:
<DISPLAYPAGE>
<FIELD NAME="SERVER" TYPE="DROPDOWN" >
<OPTION>1<OPTIO N>
<OPTION>2<OPTIO N>
<OPTION>3<OPTIO N>
</FIELD>
</DISPLAYPAGE>
I want to populate the drop down options from a database. The table
looks like this (example):
CREATE TABLE options_table (
id int primary key,
name varchar(255),
field varchar(255)
)
I read an article that would allow me to embed an SQL query using XSLT
like this (in place of <OPTIONS>):
<xslt:templat e match="options_ table[field='SERVER']">
<OPTION><xslt:v alue-of select="name/text()"/></OPTION>
</xslt:template>
Which would be equivalent of:
SELECT name FROM options_table WHERE field='SERVER';
Does anyone else have experience of describing SQL queries in XML or
parsing XSLT in python?
--
To mail remove REMOVEME. from address. 3 3091
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.
Crutcher wrote: 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.
Well, first of all, it's about mapping XPath onto a relational data
model. This is clear from the original posting:
<xslt:templat e match="options_ table[field='SERVER']">
<OPTION><xslt:v alue-of select="name/text()"/></OPTION>
</xslt:template>
Here, it makes sense to consider instances of options_table elements as
rows in the options_table table, just as described. Perhaps, if field
and name are columns in options_table, I would rather model them using
attributes:
<xslt:templat e match="options_ table[@field='SERVER']">
<OPTION><xslt:v alue-of select="@name"/></OPTION>
</xslt:template>
Is this possible or wise to do? Well, I did myself write an
XPath-to-SQL query engine, together with a simple "document relational"
mapper in order to be able to execute XPath expressions similar to
those above. However, I don't believe that my code really delivered on
the concept because...
* Generating efficient sets of queries can be tricky: a simple
descent into what appears to be an XML document needs
to involve a lot of joins to enforce the virtual "element
hierarchy".
* One has to decide whether to enforce a schema or not: if you don't
this means that XPath axes like "child" can behave like
"descendant-or-self". If you do, generating "descendant-or-self"
queries becomes very difficult (as far as I can tell and remember).
* The XPath specification states that nodes are returned in document
order - this is difficult to enforce unless you litter your tables
with additional information (again as far as I remember).
* Generating simple DOM structures for simple SQL queries is
straightforward , but generating them for arbitrarily complicated
XPath queries mapped to SQL is quite difficult. If you permit axes
like "ancestor-or-self" and "parent", or have any query that
returns a node over and over again, it's best to instantiate that
node only once in order to keep the number of instantiated
objects low and to more easily test relationships between nodes.
It's all awkward if not particularly difficult.
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.
I don't know what it is with comp.lang.pytho n/python-list these days
and the cheap put-downs. Unless you know the person you're responding
to personally, and thus the above counts as some kind of banter, you
would do better to keep the insults to yourself.
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.
Why not? 4XSLT is in Python, or at least large parts of it were.
Moreover, my XPath query experiments used a variant of PyXML's XPath
library which could quite probably have been integrated with 4XSLT,
although I didn't try it at the time.
[Patterns]
Anyway, I'm not suggesting that the XPath-to-SQL route is the right
way. The various patterns you suggest are easier to comprehend and
require a lot less magic, even if there's a bit more integration to be
done to prepare data for use by the templates. But given the existence
of XML database systems, I don't think the idea of accessing them (or
things pretending to be like them) via XML technologies is outrageous
at all.
Paul
> I don't know what it is with comp.lang.pytho n/python-list these days and the cheap put-downs. Unless you know the person you're responding to personally, and thus the above counts as some kind of banter, you would do better to keep the insults to yourself.
You are completely right, I was overly familiar.
Let me restate my central thesis.
1) It is possible to do what he is asking to do.
2) It requires expert knowledge of XSLT to do it well, and then it
would still require a bit of work.
3) There are simpler ways to do it, both using and not using xslt, than
this.
You could also do something like this:
<options ...>
<sql-hack query="select name from servers">
<option><sql-value value="name"></option>
</sql-hack>
</options>
and then do an XPath search for sql-hack nodes, and process them with
your python.
If you are happy staying on the python ranch, you could even do this:
<options ...>
<python><![CDATA[
rows = sql('select names from servers')
for row in rows:
xml('<option>%s </option>' % row[0])
]]>
</python>
</options>
With this, you find the python sections, and exec them in a context
with sql defined to do queries against your db and xml defined to parse
the xml you give it, and emit it in place of the python element.
But given the existence of XML database systems, I don't think the idea of accessing them (or things pretending to be like them) via XML technologies is outrageous at all.
No, not outrageous. But this wasn't about quering XML database systems.
This was about implementing something which looked like, but did not
act like, XSLT. It's just bad design. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ted |
last post by:
Was wondering if XSLT alone is appropriate for the following situation.
From XML, I'm creating a small website (around 50 pages) with pages that
link to each other through a nav menu and a "crumb-trail" of links. I'm
transforming the XML with XSLT through Saxon.
The nav menu and "crumb-trail" show the user where they are within the site
and is made by reflecting the XML tree structure.
My problem now is that when I want to generate...
|
by: Duane Morin |
last post by:
I fear this might be a FAQ but I can't figure out how to google for
it.
Recently we had a big bug where the source that an XSL file acted on
changed out from under it. Result, the XSL matched nothing and
important content did not make it to the final destination.
I was under the impression that an XSL could be told "You will be
acting on an XML that is valid according to the following DTD." Thus,
if the XML that it was applied...
|
by: BaKMaN |
last post by:
I am using ASP/VBScript to produce a XML file based on a AccesDB query
(using adPersistXML) and include a XSL, by itself this works nicely.
Is it possible to combine 2 separate queries into one file (using
adPersistXML) ?
eg. I have 2 tables with contain related data, however I only need one
record from one table and multiple related records from the other.
Or should I create 2 XML files and parse them using XSL (xsl:variable
|
by: Gordon Moore |
last post by:
Hi,
I'm new to using xml/xslt and although I can create an xml document
using the dataset.WriteXml statement, and I have created an xslt to
transform the xml into the output I want, I have to manually add the
xsl reference statement to the xml file.
i.e.
<?xml version="1.0" standalone="yes"?>
<?xml:stylesheet type="text/xsl" href="Questions.xsl"?> --> I have to
|
by: XML newbie: Urgent pls help! |
last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it
verifies the login information it should display the SessionID and enable
some button . I appreciate your help and thanku in advance
When I run the pgm , I get the error:
Can't parse login information. Namespace Manager or XsltContext needed. This
query has a prefix, variable or userdefined function.
I have added the Try-catch in all my functions. In...
| |
by: XML newbie: Urgent pls help! |
last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it
verifies the login information it should display the SessionID and enable
some button . I appreciate your help and thanku in advance
When I run the pgm , I get the error:
Can't parse login information. Namespace Manager or XsltContext needed. This
query has a prefix, variable or userdefined function.
I have added the Try-catch in all my functions. In...
|
by: Elhanan |
last post by:
hi..
i'm trying to figure out if i can include an extenal file of xml inside
xslt, what i need is a configuration file which xslt can query duing
transformation, (we are talking about a rather large document here.
i thought about using document function, since i'm gonna thiis called
about hunders of times i don't know the impact this would have on
performance (does xsll keeps opening closing a file?)
|
by: sani723 |
last post by:
i am fetching some data from SQL and filling it through the Adapterto in DataSet, and then passing that DataSet to the XmlDataDocument Object, like
XmlDataDocument XMLDoc = new XmlDataDocument(dsOrders);
and then again i take SqlDataAdapteradapter2 with new Query and again fill the same Dataset. means there are now two results, resulted by 2 queries
XMLDoc.DataSet.EnforceConstraints = false;
and then i am accessing that data...
|
by: kadykedar |
last post by:
I have following XML now i want to search XML using XSLT for Solution word which is in Title element.
I want to use same functionality which is provided by Like % operator in SQL queries
<casestudy>
<casestudyid>4000000187</casestudyid>
<contenttype>Case Study</contenttype>
<title>Semiconductor Solution Manufacturer Protects Confidential Communications</title>
<summary><p>The innovative and interactive environment at Axcelis...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |