如何从 XML 样本生成 XSLT
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/482759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to generate XSLT from XML samples
提问by Jan B. Kjeldsen
I am looking for a tool for semi-automaticXSLT generation.
我正在寻找一种用于半自动XSLT 生成的工具。
Given 2 XML files, source:
给定 2 个 XML 文件,来源:
<elm>XXX</elm>
and target:
和目标:
<exx>XXX</exx>
The tool should make the XSLT file, which produces the target from the source. Looking at the content, it should identify changes in level, placement, element names etc. There is no general solution to this, but I would need simple transformations only.
该工具应生成 XSLT 文件,该文件从源生成目标。查看内容,它应该识别级别、位置、元素名称等方面的变化。 对此没有通用的解决方案,但我只需要简单的转换。
Possible implementation:
可能的实现:
1. scan the source, map XML data "XXX" to element path "elm"
2. scan the target, map XML data "XXX" to element path "exx"
3. output target XML structure, output XSLT mapping of "XXX", "elm" -> "exx"
In case of conflicts manual intervention is needed. A conflict could be "XXX" in more than on place in source.
如果发生冲突,则需要手动干预。冲突可能是“XXX”,而不是源中的位置。
It would be nice if the tool was XSD/DTD aware also, for example to do manual "field" mappings.
如果该工具也能识别 XSD/DTD,那就太好了,例如进行手动“字段”映射。
Edit: clarification.
编辑:澄清。
回答by Kosi2801
I doubt that even simple transformation rules are possible to be generated automatically.
我怀疑即使是简单的转换规则也能自动生成。
For example take the XML
以 XML 为例
<family>
<father>Paul</father>
<mother>Maria</mother>
<child>Paul</child>
</family>
and the target
和目标
<person>Paul</person>
which should be a quite common combination. I could not even manually decide (without help from the one wanting the transformation) from which tag the target <person> has been created, from <father> or <child> so I doubt that an application would produce something sane here.
这应该是一个很常见的组合。我什至无法手动决定(没有想要转换的人的帮助)目标<person> 是从哪个标签创建的,从<father> 或<child> 所以我怀疑应用程序会在这里产生一些理智的东西。
Update:If some sort of drag&drop-XSLT-generation would be ok for you, there are some commercial products available, but they cannot produce XSLT from a target file. But drag&drop should be at least a better solution than writing it completely by hand:
更新:如果某种形式的拖放 XSLT 生成适合您,那么有一些商业产品可用,但它们无法从目标文件生成 XSLT。但是拖放至少应该是比完全手工编写更好的解决方案:
- WYSIWYG XSLT Designer
- Tiger XSLT Mapper (not officially available anymore)
- 所见即所得 XSLT 设计器
- Tiger XSLT Mapper(不再正式提供)
回答by Skaue
Have you checked Altova MapForce? It is not freeware, but I believe it handles what you're looking for. http://www.altova.com/mapforce.html
你检查过 Altova MapForce 吗?它不是免费软件,但我相信它可以处理您正在寻找的东西。 http://www.altova.com/mapforce.html
回答by Govind
I have used Altova Map force to generate XSLT for huge size XML and works good. You can do almost all the logics like logical, string function, math functions and user defined funtions etc., But the thing is that, when your XML is very huge spider like web sometimes confuse you lot and messy but this is expected only. And I guess manintenance may be little tough in altova.
我已经使用 Altova Map force 为巨大的 XML 生成 XSLT 并且效果很好。你可以做几乎所有的逻辑,比如逻辑、字符串函数、数学函数和用户定义的函数等,但问题是,当你的 XML 是非常巨大的蜘蛛网时,有时会让你感到困惑和混乱,但这只是预期的。我想在 altova 中维护可能有点困难。

