【发布时间】:2018-10-31 17:24:01
【问题描述】:
我是 XML 和 XSLT 的新手,我有一个输入文档,我想在其中提取前缀为 p 、 T 和 C 的元素,并计算带有根 SKU 和列表的序列号。 我尝试了很多方法,但无法使其正常工作,需要一些帮助/建议。
- 在我的 XSLT 中,我将所有带有 safix ppp 的元素复制到输出文件中。
- 在我的 XSLT 中,我将所有带有 safix c00 的元素复制到输出文件中。
- 在我的 XSLT 中,我将所有带有 saefix t0 的元素复制到输出文件中。
非常感谢任何帮助。
谢谢您,期待您的回复。
<?xml version="1.0" encoding="UTF-8"?>
<root>
<row>
<product.name>iPhoneX</product.name>
<category>phone</category>
<serial>P0001</serial>
</row>
<row>
<product.name>iPadMini</product.name>
<category>tablet</category>
<serial>T0001</serial>
</row>
<row>
<product.name>iPadMini</product.name>
<category>tablet</category>
<serial>T0002</serial>
</row>
<row>
<product.name>iPhoneX</product.name>
<category>phone</category>
<serial>P0002</serial>
</row>
<row>
<product.name>iMacPro</product.name>
<category>computer</category>
<serial>C0001</serial>
</row>
<row>
<product.name>iMacPro</product.name>
<category>computer</category>
<serial>C0002</serial>
</row>
<row>
<product.name>iPhoneX</product.name>
<category>phone</category>
<serial>P0003</serial>
</row>
<row>
<product.name>iPhoneX</product.name>
<category>phone</category>
<serial>P0004</serial>
</row>
<row>
<product.name>iPhoneX</product.name>
<category>phone</category>
<serial>P0005</serial>
</row>
预期的输出格式如下:
<?xml version="1.0" encoding="UTF-8"?>
<Inventory>
<SKU>
<category>phone</category>
<product.name>iPhoneX</product.name>
<product.count>5</product.count>
<list>P0001</list>
<list>P0002</list>
<list>P0003</list>
<list>P0004</list>
<list>P0005</list>
</SKU>
<SKU>
<category>tablet</category>
<product.name>iPadMini</product.name>
<product.count>2</product.count>
<list>T0001</list>
<list>T0002</list>
</SKU>
<SKU>
<category>computer</category>
<product.name>iMacPro</product.name>
<product.count>2</product.count>
<list>C0001</list>
<list>C0002</list>
</SKU>
</Inventory>
我尝试了很多方法,但无法让它发挥作用,需要一些帮助/建议。
非常感谢任何帮助。
谢谢您,期待您的回复。
我能做什么?
【问题讨论】:
-
我改进了您的 XML 代码的格式,但我无法改进 XSLT 代码,因为它无效。因此,在您获得有价值的答案之前,您必须修复您的 XSLT 代码。
-
这似乎是一个相对简单的分组问题(进行搜索)。除了 P、T 和 C 之外,输入是否还有其他前缀?如果是,它们是否应该包含在输出中?
标签: xml xslt xslt-2.0 root sku