【发布时间】:2014-09-08 22:41:21
【问题描述】:
我是xslt的新手,我有两个xml文件如下file1.xml:
<?xml version="1.0" encoding="UTF-8"?>
<people-data id="test-id" timestamp="20014-03-30T09:00:00">
<person>
<id>12345</id>
<first-name>John</first-name>
</person>
<person>
<id>67890</id>
<first-name>Mike</first-name>
</person>
<person>
<id>11111</id>
<first-name>Dan</first-name>
</person>
</people-data>
第二个xml文件如下file2.xml:
<?xml version='1.0' encoding='UTF-8'?>
<people-appointment-data>
<person-data>
<id>12345</id>
<first-name>John</first-name>
<appointments>
<appointment>
<code>5124</code>
<pass>14920329324</pass>
<states>
<state>IL</state>
<state>IN</state>
</states>
</appointment>
<appointment>
<code>1001</code>
<pass>14921119324</pass>
<states>
<state>NV</state>
<state>CA</state>
</states>
</appointment>
</appointments>
</person-data>
<person-data>
<id>67890</id>
<first-name>Mike</first-name>
<appointments>
<appointment>
<code>6666</code>
<pass>14920</pass>
<states>
<state>AK</state>
<state>MA</state>
</states>
</appointment>
</appointments>
</person-data>
</people-appointment-data>
我试图使用 xslt 实现的是将约会信息复制到第一个 xml 文件中,过滤 id 标签上的匹配项。
如果 id 不匹配,这就是我期望的输出结果,file1.xml 中的信息将被保留:
<?xml version="1.0" encoding="UTF-8"?>
<people-data id="test-id" timestamp="20014-03-30T09:00:00">
<person>
<id>12345</id>
<first-name>John</first-name>
<appointments>
<appointment>
<code>5124</code>
<pass>14920329324</pass>
<states>
<state>IL</state>
<state>IN</state>
</states>
</appointment>
<appointment>
<code>1001</code>
<pass>14921119324</pass>
<states>
<state>NV</state>
<state>CA</state>
</states>
</appointment>
</appointments>
</person>
<person>
<id>67890</id>
<first-name>Mike</first-name>
<appointments>
<appointment>
<code>6666</code>
<pass>14920</pass>
<states>
<state>AK</state>
<state>MA</state>
</states>
</appointment>
</appointments>
</person>
<person>
<id>11111</id>
<first-name>Dan</first-name>
</person>
</people-data>
【问题讨论】:
-
请说明您使用的 XSLT 版本 - 1.0 或 2.0。
-
你能指导我使用 XSLT 1.0 吗,下面给出的当前解决方案不起作用。 @michael.hor257k
-
虽然“当前的解决方案”非常糟糕,但它仍然应该“有效”,因为它应该得到每个人的约会。所以我建议你先让事情正常工作。
-
感谢您的及时回复,我的 xml 文件中有一个错误,带有结束标记。下面给出的解决方案是有效的。你有什么改进的建议?我对 xslt 很陌生,还在学习。 @michael.hor257k