【发布时间】:2019-05-16 09:55:04
【问题描述】:
我需要一些帮助。我对 XSLT 有点陌生。
我知道在 2.0 中您可以使用 For-Each-Group 来解决我的问题,但我仅限于 1.0。
我需要使用“group-starting-with”之类的功能对平面 XML 进行分组。
这只是一个例子,但我的实际问题非常相似。
我有这个 XML:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<xpto name="1">ABC</xpto>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
<xpto name="2">ABC</xpto>
<xpto name="1">ABC</xpto>
<title>Hide your heart</title>
<artist>Bob Dylan</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
<xpto name="2">ABC</xpto>
</catalog>
我希望它是:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<group>
<xpto name="1">ABC</xpto>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
<xpto name="2">ABC</xpto>
</group>
<group>
<xpto name="1">ABC</xpto>
<title>Hide your heart</title>
<artist>Bob Dylan</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
<xpto name="2">ABC</xpto>
</group>
</catalog>
所以我想在每次出现以下内容时对元素进行分组:
<xpto name="1">ABC</xpto>
有没有办法用 XSLT 1.0 做到这一点?
非常感谢!
【问题讨论】:
-
嗨,欢迎来到 StackOverflow!你能提供你迄今为止尝试过的东西吗?
标签: xml xslt xslt-1.0 xslt-grouping