1

I am new to those two technologies, I sketched their roles in generating an HTML out of raw XML file as I understood in these steps(Please correct me if I was wrong):

  1. XML data source (database, RSS, ...)
  2. XQuery (Data manipulation FLWR)
  3. XSLT (Data representation through templating)
  4. The resulting XHTML document to be delivered

I am wondering about the technical details of using them, to be specific, here are the questions:

  • How to implement XQuery in a PHP web server (I am using WAMP suite).
  • How can I request .xq page (can I do that directly, or should I use a CGI to do that?)
  • How can I pass the resulting XML page from XQuery call to XSLT for templating?

Could you give me some pointers the development environment to create a website using these technologies, thanks.

-- Update: I understand now that difference between XQuery and XSLT is a difference in point of view since two different working groups are maintaining them, both will do the job though in different approaches. I am using XSLT only for both data operations and representation, I am implementing structured templating approach which is found here XSLT Abstractions in order to organize the work a little bit.

Community
  • 1
  • 1
Y.H.
  • 2,687
  • 1
  • 29
  • 38

1 Answers1

2

I have a system that works along the lines you describe. It runs like this;

Inputs

  1. The XML data is a plain text file eg. "data.xml".
  2. The XSL stylesheet is a plain text file eg. "style.xsl".
  3. The xquery is a plain text file eg. "test.xq".
  4. An xquery processor is running as a service on port 2409. (More about this below.)

Flow

  1. A PHP script eg. "index.php" runs. It contacts the xquery processor like this;

    $xml = file_get_contents("http://localhost:2409/test.xq");

  2. The test.xq query is executed by the xquery processor. The test.xq query uses the doc function to load the data;

    declare variable $root := doc("data.xml");

    When test.xq finishes, the result is returned by the xquery processor to index.php.

  3. Back in index.php, $xml now contains the result of the test.xq xquery. An XSLT processor is invoked to transform the XML into XHTML. The PHP code is something like;

    $doc = new DOMDocument();
    $doc->loadXML($xml);
    $stylesheet = new DOMDocument();
    $stylesheet->load("style.xsl");
    $processor = new XSLTProcessor();
    $processor->importStylesheet($stylesheet);
    $xhtml = $processor->transformToXML($doc);
    echo $xhtml;
    

The only part of all that which is not achievable using standard components is the xquery processor. I had to write that bit using a Java servlet to invoke the Saxon xquery processor. Both Java and Saxon are free but it still took a lot of learning to get it working.

You can see it working here.

I like this technique because a) it separates logic from presentation and b) it runs fast.

Nigel Alderton
  • 2,265
  • 2
  • 24
  • 55