This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: read records from database in XSLT


Hi, Stuart,

I don't know if mysql can do what the Microsoft SQL does. But I'll give it 
a try. On the other hand, I'm thinking that, if the parameter for 
document() can be a URI, can I write a java servlet which takes the query 
passed through the url and return the query results? But the question is, 
in what format the output should be in? Should it be in plain text format 
or html? Is this a matter of passing the content type in the header?  

Thanks a lot for your help and your suggestions.

Ming

 On Tue, 14 May 2002, Stuart Celarier wrote:

> Ming,
> 
> 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.
> 
> Cheers,
> Stuart
> 
> [1] http://www.sellsbrothers.com/conference
> 
> 
> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of Ming
> Sent: Tuesday, May 14, 2002 16:00
> To: xsl-list@lists.mulberrytech.com
> Subject: [xsl] read records from database in XSLT
> 
> Hi,
> 
> I have a question regarding reading records from a database in XSLT.
> 
> I have the following xml file:
> 
> <files>
> <file db="db1" name="/record/2233/21/1/12_mmish"  />
> <file db="db2" name="/record/2233/21/2/34_ytrrm"  />
> </files>
> 
> 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:
> <xml>
>   <db1>
>    <title> title1 </title>
>   </db1/>
> </xml>
> 
> 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.
> 
> Ming
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]