XSLT 与 XQuery
我对这两种技术很陌生,我概述了它们在从原始 XML 文件生成 HTML 中的作用,正如我在这些步骤中所理解的那样(如果我错了,请纠正我):
- XML 数据源(数据库、RSS...)
- XQuery (数据操作 FLWR)
- XSLT(通过模板进行数据表示)
- 要交付的 XHTML 文档
我想知道使用它们的技术细节,具体来说,以下是问题:
- 如何在 PHP Web 服务器中实现 XQuery(我我正在使用 WAMP 套件)。
- 我如何请求 .xq 页面(我可以直接执行此操作,还是应该使用 CGI 执行此操作?)
- 如何将 XQuery 调用生成的 XML 页面传递到 XSLT 进行模板化?
您能否给我一些使用这些技术创建网站的开发环境的指导,谢谢。
-- 更新: 我现在明白,XQuery 和 XSLT 之间的差异是观点上的差异,因为两个不同的工作组正在维护它们,但两者都会以不同的方法完成这项工作。 我仅将 XSLT 用于数据操作和表示,我正在实现结构化模板方法,可以在此处找到 XSLT Abstractions 以便稍微组织一下工作。
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):
- XML data source (database, RSS, ...)
- XQuery (Data manipulation FLWR)
- XSLT (Data representation through templating)
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个按照您描述的方式工作的系统。它是这样运行的;
输入
流
PHP 脚本,例如。 “index.php”运行。它像这样联系 xquery 处理器;
<代码>
$xml = file_get_contents("http://localhost:2409/test.xq");
test.xq 查询由 xquery 处理器执行。 test.xq查询使用doc函数加载数据;
<代码>
声明变量 $root := doc("data.xml");
当 test.xq 完成时,结果由 xquery 处理器返回到 index.php。
回到index.php,$xml 现在包含test.xq xquery 的结果。调用 XSLT 处理器将 XML 转换为 XHTML。 PHP 代码类似于;
使用标准组件无法实现的唯一部分是 xquery 处理器。我必须使用 Java servlet 来调用 Saxon xquery 处理器来编写该部分。 Java 和 Saxon 都是免费的,但仍然需要大量学习才能使其正常工作。
您可以在此处查看它的工作情况。
我喜欢这种技术,因为 a) 它将逻辑与表示分离,b) 它运行速度快。
I have a system that works along the lines you describe. It runs like this;
Inputs
Flow
A PHP script eg. "index.php" runs. It contacts the xquery processor like this;
$xml = file_get_contents("http://localhost:2409/test.xq");
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.
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;
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.