【发布时间】:2016-01-03 16:17:38
【问题描述】:
我是 XSLT 的新手,我正在尝试将以下 xml 中的数据解析为 html,其中每个 root/Quote/Quotes 是一个 Vehicle,Vehicle 的值是根据相应报价中的 QuoteId 确定的,我需要根据 QuoteID 并排显示 Quote-1 和 Quote-2 和 QuoteID 在 1st <Sequence> 和 2nd <Sequence> 下的相应值,我需要显示所有根/Quotes/Quote 中的所有不同元素它的值,或者如果任何元素或元素的值不存在 - 我需要显示“未找到”
有可能第一个 <Sequence> 可以有 root/Quotes/Quote's 和 <SequenceID> 的 1、2、3 和第二个 <Sequence> 可以有 <SequenceID> 的 1 和 3,在这种情况下我需要将 Quote-2 的所有标签值显示为“未找到”
输入 XML
<HTMLData>
<Sequence>
<QuoteTitle>Quote-1</QuoteTitle>
<Response>
<root>
<Quotes>
<Quote>
<Element1 value="122"/>
<Element2 value="233"/>
<Element3 value="344"/>
<Element4 value="455"/>
<QuoteID value="1"/>
</Quote>
</Quotes>
<Quotes>
<Quote>
<Element1 value="466"/>
<Element2 value="577"/>
<Element7 value="688"/>
<Element8 value="799"/>
<QuoteID value="2"/>
</Quote>
</Quotes>
</root>
</Response>
</Sequence>
<Sequence>
<QuoteTitle>Quote-2</QuoteTitle>
<Response>
<root>
<Quotes>
<Quote>
<Element1 value="233"/>
<Element10 value=""/>
<Element11 value=""/>
<Element12 value="123"/>
<QuoteID value="1"/>
</Quote>
</Quotes>
<Quotes>
<Quote>
<Element13 value="123"/>
<Element14 value="234"/>
<Element15 value="456"/>
<QuoteID value="2"/>
<Element16 value="654"/>
</Quote>
</Quotes>
<Quotes>
<Quote>
<Element13 value="234"/>
<Element14 value="443"/>
<Element15 value="654"/>
<Element16 value="544"/>
<QuoteID value="3"/>
</Quote>
</Quotes>
</root>
</Response>
</Sequence>
</HTMLData>
期望的输出
<table xmlns:xs="http://www.w3.org/2001/XMLSchema" border="1">
<tr>
<th class="border-top border-bottom border-left border-right">Type</th>
<th class="border-top border-bottom border-left border-right">Vehicle</th>
<th class="border-top border-bottom border-left border-right">Label</th>
<th class="border-top border-bottom border-left border-right">Quote-1</th>
<th class="border-top border-bottom border-left border-right">Quote-2</th>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right">Motor</td>
<td class="border-top border-bottom border-left border-right">Vehicle1</td>
<td class="border-top border-bottom border-left border-right">Element1</td>
<td class="border-top border-bottom border-left border-right">122</td>
<td class="border-top border-bottom border-left border-right">233</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element2</td>
<td class="border-top border-bottom border-left border-right">233</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element3</td>
<td class="border-top border-bottom border-left border-right">344</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element4</td>
<td class="border-top border-bottom border-left border-right">455</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">QuoteID</td>
<td class="border-top border-bottom border-left border-right">1</td>
<td class="border-top border-bottom border-left border-right">1</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element7</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element8</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element10</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element11</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element12</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">123</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element13</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element14</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element15</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element16</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right" colspan="count()">Motor</td>
<td class="border-top border-bottom border-left border-right">Vehicle2</td>
<td class="border-top border-bottom border-left border-right">Element1</td>
<td class="border-top border-bottom border-left border-right">466</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element2</td>
<td class="border-top border-bottom border-left border-right">577</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element3</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element4</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">QuoteID</td>
<td class="border-top border-bottom border-left border-right">2</td>
<td class="border-top border-bottom border-left border-right">2</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element7</td>
<td class="border-top border-bottom border-left border-right">688</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element8</td>
<td class="border-top border-bottom border-left border-right">799</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element10</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element11</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element12</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element13</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">133</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element14</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">234</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element15</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">456</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element16</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">654</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right" colspan="count()">Motor</td>
<td class="border-top border-bottom border-left border-right">Vehicle3</td>
<td class="border-top border-bottom border-left border-right">Element1</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element2</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element3</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element4</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">QuoteID</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element7</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element8</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element10</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element11</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element12</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element13</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">234</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element14</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">443</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element15</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">654</td>
</tr>
<tr>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right"></td>
<td class="border-top border-bottom border-left border-right">Element16</td>
<td class="border-top border-bottom border-left border-right">Not Found</td>
<td class="border-top border-bottom border-left border-right">544</td>
</tr>
</table>
【问题讨论】:
-
您的问题不清楚。您的输入中没有
。而且很难理解输入到输出的映射——尤其是。当某些值不唯一时。 -
对不起,我的意思是 QuoteID,如果值存在,我需要所有元素的名称都存在于所有具有值的车辆中,如果不存在,值应该是“未找到”
-
每个
代表一个事务(命名为 值),每个 Quotes/Quote 代表该事务下的一个 Quote,我的要求是显示 具有的值相同的
在不同的 在 HTML 中并排。提前致谢!