RE: [xsl] read records from database in XSLT

Subject: RE: [xsl] read records from database in XSLT
From: "Stuart Celarier" <stuart@xxxxxxxxxxx>
Date: Tue, 14 May 2002 17:49:54 -0700

I cannot speak to MySQL, but I saw a great demonstration of accessing a
database from XSLT in Craig Andera's talk at the Web Services Developers
Conference [1] in March. In his presentation he implemented a Web
Service using XSLT, Microsoft SQL Server and IIS (Microsoft's web
server). Very cool. Perhaps these notes will guide you in working with
your own tools.

The key concept is that the document() function is called with a string
parameter, that string is treated as a URI. That URI may be the URL for
a file or any other resource the server can serve up. Using MS SQL
Server, the database is exposed as an HTTP endpoint using the IIS
Virtual Directory Management for SQL Server utility. That makes it
possible to query the database via a URL, something of the form

  http://localhost/myDatabase?sql=SELECT * ... FOR XML AUTO

with all the space characters properly escaped for a URL (I've left them
out for clarity). The "localhost" term is the local name for the web
server, replace that with the real server name if the database is being
served up from another machine. This sort of URL can then be passed into
XSLT's document() function to perform a query against the database and
return it as an XML document.

So the problem you need to solve isn't really with XSLT, it is with
exposing your database through a web server so that you can access it
with a URL. Can you do that with MySQL? Good luck and let me know if you
have success.



-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Ming
Sent: Tuesday, May 14, 2002 16:00
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] read records from database in XSLT


I have a question regarding reading records from a database in XSLT.

I have the following xml file:

<file db="db1" name="/record/2233/21/1/12_mmish"  />
<file db="db2" name="/record/2233/21/2/34_ytrrm"  />

And the name attribute is a key in a mysql table. What I want is the
value of the key. So, I can use "select recordvalue from Record where
keyvalue = '/record/2233/21/1/12_mmish'" to get the record value from
the table.

The record value is actually in xml format like this:
   <title> title1 </title>

What I need is to read the whole value in my stylesheet using something
like <xsl:variable name='record' select="document(@name)/xml"/>. But
since the name attribute is not the path to a xml file, I cannot use
this method.

Can anyone give me some suggestions on how to approach this or some
information I can know more about using queries in my stylesheet?

Thanks a lot.


 XSL-List info and archive:

 XSL-List info and archive:

Current Thread