使用 XSLT 将 XML 转换为 SQL [英] Transform XML using XSLT to SQL

查看:39
本文介绍了使用 XSLT 将 XML 转换为 SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我无法控制的原因,我将获得一个 XML 文件和一个 XSLT 文件,该文件可以将 XML 文件转换为 SQL 代码或错误.

for reasons beyond my control, I will get an XML file, and an XSLT file that can convert the XML file to either SQL code or to an error.

现在让我们假设我们可以相信提供 XML 文件的人不会在 XML 中包含危险的结构...

Lets just assume for now that we can trust the one providing the XML file not to include dangerous constructs in the XML...

我什至不知道我是否应该使用 SimpleXML、XMLWriter、DOMDocument 或其他东西.另外,我应该使用 XSLTProcessor 还是其他什么?

I do not even know if I should use SimpleXML, XMLWriter, DOMDocument or something else. Also, should I use XSLTProcessor or something else?

在 PHP 中实现此功能的最佳方法是什么?

What is the best way to implement this in PHP?

谢谢,

推荐答案

如果我理解了你的问题,并且提供了 xmldata 和样式表,你可以简单地像这样转换它:

If I've understood your question, and xmldata and stylesheet are provided, you can simply transform it like this:

$data = new DOMDocument();
$data->loadXML('<yourxmldata />';

$stylesheet = new DOMDocument();
$stylesheet->loadXML('<yourxslstylesheet/>');

$processor = new XSLTProcessor(); 
$processor->importStylesheet($stylesheet);
var_dump($processor->transformToXML($data));

这篇关于使用 XSLT 将 XML 转换为 SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆