这是我的XML的
<?xml version="1.0" encoding="UTF-8"?>
<update-all-attributes>
<document name="http://blah">
<price>111 USD</price>
<color>red</color>
<size>comfort</size>
<cost>00012-40</cost>
<shipping>US::Ground:0.00</shipping>
<cost>00012-40</cost>
<price>111 USD</price>
<color>red</color>
<size>comfort</size>
<cost>00012-40</cost>
<shipping>US::Ground:0.00</shipping>
<cost>00012-40</cost>
<price>111 USD</price>
<color>red</color>
<size>comfort</size>
<shipping>US::Ground:0.00</shipping>
<price>111 USD</price>
<color>red</color>
<size>comfort</size>
</document>
<document name="http://blahblah">
<price>110 USD</price>
<color>blue</color>
<size>super</size>
<cost>00012-41</cost>
<shipping>US::Ground:0.01</shipping>
<cost>00012-41</cost>
<price>110 USD</price>
<color>blue</color>
<size>super</size>
<shipping>US::Ground:0.01</shipping>
<cost>00012-41</cost>
<price>110 USD</price>
<color>blue</color>
<size>super</size>
<shipping>US::Ground:0.01</shipping>
<price>110 USD</price>
<color>blue</color>
<size>super</size>
</document>
</update-all-attributes>
我想我的最终XML作为
<?xml version="1.0" encoding="UTF-8"?>
<document name="http://blah">
<price>111 USD</price>
<color>red</color>
<size>comfort</size>
<cost>00012-40,00012-40,00012-40,00012-40</cost>
<shipping>US::Ground:0.00,US::Ground:0.00,US::Ground:0.00</shipping>
</document>
<document name="http://blahblah">
<price>110 USD</price>
<color>blue</color>
<size>super</size>
<cost>00012-41,00012-41,00012-41,00012-41</cost>
<shipping>US::Ground:0.01,US::Ground:0.01,US::Ground:0.01</shipping>
</document>
这是用于创建多值属性(感谢michael.hor257k)的XSLT。 这是给我复制其他属性值 -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="document">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="@*|price"/>
<xsl:copy-of select="@*|color"/>
<xsl:copy-of select="@*|size"/>
<cost>
<xsl:for-each select="cost">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</cost>
<shipping>
<xsl:for-each select="shipping">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</shipping>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
如何修改我的XSLT 1.0剥离重复的属性,以及保持选定的属性为多值? 我有多个文档元素,所以应该对所有的文档元素的工作。