【发布时间】:2013-10-23 13:02:38
【问题描述】:
我有一个大的 xml 文档,如下所示:
<?xml version="1.0" encoding="UTF-8" ?>
<Data>
<aTable>
<aTableRow Col1="1" Col2="someText"/>
<aTableRow Col1="2" Col2="newText"/>
...
</aTable>
<anotherTable>
<anotherTableRow Col3="someText" Col4="42"/>
<anotherTableRow Col3="myText" Col4="34"/>
...
</anotherTable>
...
</Data>
我需要在相应的 SQL INSERT 语句序列中转换文档。比如:
INSERT INTO aTable (Col1, Col2) VALUES (1, "someText")
我已经有了从“表”到对应SQL语句的转换,但是xslt输出是按照文档的相同顺序生成的。
有没有办法在 aTable 之前拥有例如 anotherTable?
编辑
感谢 cmets 和回答。阅读它们,我意识到我最初的问题并不是那么清楚。我会尝试添加更多细节。
我已经制作了一个模板,它可以在一系列插入语句中正确转换 xml 数据,假设该模板名为“insertGeneration”。
然后我写了类似的东西:
<xsl:template match="Data/anotherTable">
<xsl:call-template name="insertGeneration"/>
</xsl:template>
<xsl:template match="Data/aTable">
<xsl:call-template name="insertGeneration"/>
</xsl:template>
我希望按此顺序生成输出,即所有INSERT INTO anotherTable 在所有INSERT INTO aTable 之前。但生成的顺序与源文档相同。
我需要一个特定的顺序,否则在执行 SQL 脚本时我可能会违反外键约束。
我的 xslt 处理器是 Visual Studio 2005。好吧,不是一个紧凑的 xslt 处理器;-)
【问题讨论】:
-
这将有助于查看您当前的转换。