【发布时间】:2014-03-21 20:19:02
【问题描述】:
我一直在寻找为多个 XML 创建一个 XSL。下面是示例 XML,它是众多 XML 之一。不同之处在于<ItemRequest> 代替<m.Currency> 还有其他元素。我只需要显示应该与所有 XML 兼容的 ItemRequest。
<?xml version="1.0" standalone="yes" ?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>
<ServiceRequest xmlns:m="urn:messages.service.com"
xmlns="urn:control.services.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RequestHeader>
<Service>Blah</Service>
<Operation>Blah1</Operation>
</RequestHeader>
<m:ItemRequest>
<ServiceRequest xmlns="urn:control.com" xmlns:m="urn:messages.service.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RequestHeader>
<Service>Blah</Service>
<Operation>Blah2</Operation>
</RequestHeader>
<m:Currency>
<m:MaintType>a</m:MaintType>
<m:BackOffice>b</m:BackOffice>
<m:Code>c</m:Code>
<m:Number>%00</m:Number>
<m:EditCode>1</m:EditCode>
</m:Currency>
</ServiceRequest>
</m:ItemRequest>
</ServiceRequest>
输出:类似于
<h1>Operation: Currency</h1>
<table>
<tr>
<td>MainType</td>
<td>BackOffice</td>
<td>Code</td>
<td>Number</td>
<td>EditCode</td>
</tr>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
<td>%00</td>
<td>1</td>
</tr>
</table>
【问题讨论】:
-
您的 xml 格式不正确。您的序言应该是
<?xml version="1.0" encoding="UTF-8"?>,并且您的样式表处理说明不完整。 -
对不起。我是stackoverflow的新手。我确实格式化了xml代码。正如你提到的prolog和上面一样。
-
您确定可以在
m:ItemRequest中包含ServiceRequest吗?您是否有一个 XSD 来描述您可能作为输入的不同 XML? -
您还有两个不同的默认命名空间:
urn:control.services.com用于外部ServiceRequest中的元素,urn:control.com用于内部ServiceRequest中的无前缀元素。对吗?