Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2009, 06:32 AM
Authorized User
 
Join Date: Mar 2009
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default xquery my site's xml files - practical implementation?

Come to think of it there is one final thing that's been bugging me and that's how to actually implement an XQuery file?

I have tested this xquery against my xml file and it works. Here's the xquery
Code:
declare namespace geo = "http://www.dur.ac.uk/geo-engineering";
declare namespace gml = "http://www.opengis.net/gml";

for $x in doc("Slope.xml")/geo:slopeData/geo:case/geo:slope/geo:toe/geo:location/gml:Point[@srsName='EPSG:27700']
return $x/gml:pos
Only a simple example (I have created more advanced ones ! So this simply returns the values requested from within the file Slope.xml given that the xquery file is placed in the same directory. I have used oXygen to check it.

If a user comes on to my site and sees a HTML table listing all of the Slope.xml files added to the system (whereby the table is updated by a php script each time a new one is submitted) but wants to find all of the files that can match some XQuery expression (such as the one above) then how does he do it? I guess I need to provide some functionality for this process, in which case, what can I do to allow this? I have jQuery-powered sorting fields for my table columns but a user may wish for a more in depth ordering according to some other content from the XML files stored. (The Slope.xml files are stored in a location 'SlopeCase/inventory/Case[ID]/Slope.xml' (where [ID] is the case's ID number).

The simplest example would be to query these files with 'retrieve all of the Slope.xml files that have a slope angle of greater than 30degrees'.

OK you probably get my point by now! I'm just confused as to how this is implemented in practice.

Thanks

edit: Just to clarify, I am talking about an online way of achieving this. I realise that I could write some scripts for them that query from their desktop to the site, such as :
Code:
declare namespace geo = "http://www.dur.ac.uk/geo-engineering";
declare namespace gml = "http://www.opengis.net/gml";
for $x in doc("http://www.example.com/SlopeCase/inventory/[ID]/Slope.xml")/geo:slopeData/geo:case/geo:slope/geo:toe/geo:location/gml:Point[@srsName='EPSG:27700']
return $x/gml:pos
I realise most people using the site will probably have XML editors that can perform queries such as this, but some may not and may wish to search current submissions that relate to their slope problem (case-based design help). I would therefore ultimately like to provide form-like XQueries - for example with the slope angle idea there could be a form which specifies the slope angle parameters they wish to search for, these submit in to the xQuery form and then show them the resultant list of matches cases. I guess all of this is possible and perhaps not that tricky ?

The eventual idea is to be able to query all known sites/servers that hold this form of XML application data and return results of interest to the user. So then the database is essentially all over the world. To begin with though it would be nice if I could actually perform simple searches on my own site but this is what I've described above. thanks
 
Old April 23rd, 2009, 07:32 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The way you search across multiple files is typically by using the collection() function. The details of how this works are likely to vary from one product to another. Saxon allows the files making up the collection to be selected using a URI of the form "http://my.com/datadir?select=*.xml;recurse=yes", or by reference to a catalog file that lists the files in the collection.

You need to be aware that searching a collection in this way is likely to be much less efficient than using an XML database.

Your second question is about how to generate a query from data entered on a form. I'm not sure how to answer that - just do it!
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 23rd, 2009, 07:36 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Your second question is about how to generate a query from data entered on a form. I'm not sure how to answer that - just do it!

Taking care, of course, to protect against injection attacks. In the case of Saxon, it's safest in such cases to disable use of extension functions which could access your local filestore.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 23rd, 2009, 07:40 AM
Authorized User
 
Join Date: Mar 2009
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

Ok I think I'm getting the picture. So essentially I could create an input window where the user could put the xquery code and then once submitted I could use a php script to direct the code to saxon (as with the xsl translations) and return the result to a new file which is then displayed to them?

For some reason I have been maybe overcomplicating its usage in my head. Do you happen to know of simple examples that work in a similar fashion to this? I only seem to be able to find fairly abstract things such as a sandbox site or something.

edit: I'm unlikely to have time to implement this for this project, unless I work on it after the hand-in (which I probably will). I'm more interested really in making sure I understand how it could be done so that I can talk about it in my end proposals for further work.

Last edited by jamesdurham; April 23rd, 2009 at 07:42 AM..
 
Old April 23rd, 2009, 07:49 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Yes, in principle it's very simple. Read the user's input, convert it into a query, call Saxon, directing the output back to the user.

Saxon's API is Java or .NET, though, so calling from PHP presents some extra challenges.

Of course you can make it more complicated, and perhaps you should. For example it's not clear how you want to display the results of the query. Some people make a practice of splitting the query that finds the data from a separate process (typically XSLT) that renders the data for display. As things become more complex it can be useful to use a pipeline processor such as Orbeon for your framework, to reduce repetitive Java coding and increase flexibility.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 23rd, 2009, 08:27 AM
Authorized User
 
Join Date: Mar 2009
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

I've looked at Orbeon for their use of XForms as XForms kept on causing me issues in various browsers. I was hoping to use XForms to present fields online that people could fill in in order to generate simple slope pages according to my schema. That way they didn't have to directly deal with using XML styling. For my quantitative info people would practically need to use the XML directly.

I have already written (with some help from a friend) a php script which deals with schema validation of an uploaded file, calling Saxon to perform about 5translations and then returning the results to a newly generated case folder within my inventory folder. I don't imagine it would be too much different to direct the XQuery to Saxon in a similar method? (Using Java Saxon.) I've included a bit of XQuery code to check the the filetype and first couple of elements in the submitted XML before it then validates it against the schema - this is hopefully to prevent bad data being submitted.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting practical with perl ZORCH Perl 2 April 29th, 2007 10:00 PM
book - "XML Design and Implementation" Juryi All Other Wrox Books 2 May 30th, 2004 02:17 PM
XQuery sonicDace XML 2 March 19th, 2004 05:45 PM
The implementation of XML-RPC Client for COM hionghong_81 XML 1 June 5th, 2003 04:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.