我目前有这种类型的请求。问题是现有代码只能管理一个属性块。我需要剪切属性块并创建N个新块。
输入:
<Request>
<Attributes>
<Attribute>
<Complimentary>
Test1
</Complimentary>
</Attribute>
<Attribute>
<Complimentary>
Test2
</Complimentary>
</Attribute>
<Attribute>
<Complimentary>
TestN
</Complimentary>
</Attribute>
</Attributes>
</Request>
输出:
<Request>
<Attributes>
<Attribute>
<Complimentary>
Test1
</Complimentary>
</Attribute>
</Attributes>
<Attributes>
<Attribute>
<Complimentary>
Test2
</Complimentary>
</Attribute>
</Attributes>
<Attributes>
<Attribute>
<Complimentary>
TestN
</Complimentary>
</Attribute>
</Attributes>
</Request>
提前致谢
答案 0 :(得分:1)
如果我读得正确,你想做:
XSLT 1.0
<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="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Attributes">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Attribute">
<Attributes>
<xsl:copy-of select="."/>
</Attributes>
</xsl:template>
</xsl:stylesheet>