Subject:Pulling in dynamic data from PHP for Xquery Author:Steve Cox Date:25 Nov 2005 06:48 AM
Hi,
Just atarted playingw thi Stylus Studio - very impressed. I'm using XML and Xqueries to process old database tables into a new CRM system based on MYSQL. One thing I need it to do in the migration/transformation is to attach a guid record to each row element - effectively the new ID for each record going back into the final table.
Long story, but it's best to do it at this poaint as the IDs will be referecnes in other tables that will be gererated by various xqueries along the way.
The guid generator is a specific bit of PHP coding using the CRM systems included PHP libraries. I can generate the list either using a standard command line call ("c:\php\php.exe -f c:\test\guid.php") or I can generate it via a web page (eg. http;//localhost/guid.php). This latter php web page can either just present the guid code eg.
Because of the environments and data sources, I can't really tag the old database records with a guid, so they need to be tagged onto each new row for each new table when they are created. Obviously, it makes sense to do this in the xqueries transforming the data but I can't see how to do this.
I've tried setting up the source document in the xqueries mapper but it only ever generates one guid that is used for all records - it looks like the php page is only 'fired' once and the result kept statically. Is there a way to dynamically run the page and join the resultant guid for each row in an XML document?
Any thoughts on how to do this; if I'm approaching the whole thing incorrectly; alternative methods etc?
Subject:Pulling in dynamic data from PHP for Xquery Author:(Deleted User) Date:28 Nov 2005 09:09 AM
Steve,
This is a large complicated post; please tell me if I understand the question correctly. I think you have set a default input URL in the xquery scenario (http://localhost/guid.php ???). In the xquery, you read from this input URL several times, but it only gets opened and read once, so you only get one guid.
If this is what you are doing, then it is behaving as designed. Stylus opens the default input URL exactly once, and builds some type of DOM (depending on which xquery processor is being used.) Then the xquery processor accesses that DOM as many times as needed.
You might try using the doc function: doc("http://localhost/guid.php"). Depending on which xquery processor you use, it MIGHT open and read the URL each time it us used.
Which processor are you using? Is this something which will always be run from inside Stylus Studio, or do you plan to deploy it and use a separate processor? Knowing the environment will make it easier to suggest an appropriate solution.
Subject:Pulling in dynamic data from PHP for Xquery Author:Steve Cox Date:28 Nov 2005 09:26 AM
Hi,
Yes - that's pretty much the issue I have - what I'm effectivily after is my own xquery version of the xslt generate-id with my own id specification. As this spec is from a PHP script, the only option I see is to join it against the php page that generates this id.
As for the processor, I'm not sure yet. I was probably going to go for the one built into stylusstudio but can you recommend one that might achieve the above?
Subject:Pulling in dynamic data from PHP for Xquery Author:(Deleted User) Date:28 Nov 2005 10:12 AM
Steve,
If you are planning to use our built-in processor, you could write a simple java extension function to generate the guid.
If, on the other hand, you want to investigate other processors, you have a couple of choices. Open the scenario dialog for your xquery and click on the Processor tab. Select the Saxon processor, and then see if it satisfied your needs. The non-validating version of that processor is available at no charge and would be a fine choice if it does what you need.
If you have other issues relating to optimized database access, you could consider the DDXQ xquery processor. See the video tutorial at:
Subject:Pulling in dynamic data from PHP for Xquery Author:(Deleted User) Date:29 Nov 2005 02:43 PM
Steve,
Let me add something to that last reply.
It seems that the doc(...) function is required to be stable, that is if you execute it 2 times with the same argument, it will always return the same nodeset, that is, you cant get your guid without doing something clever. Some possibilities:
1) each time you call doc, modify the url by adding something unique (the last guid?) as an unused parameter &unused=blah. This has the disadvantage of clogging your memory with an arbitrary number of (small) document trees.
2) If you are using the Stylus Studio builtin processor, it is pretty easy to write a java extension function in which you can do almost anything.
3) If you are using the Saxon processor, there is a function
discard-document(...) which does just what you want. Use it like this:
let $guid := saxon:discard-document(doc('http:...'))/records/guid
Each time you call it that way, it will fetch the http page anew.