2016-12-16 184 views
0

我目前有这种类型的请求。问题是现有的代码只能管理一个属性块。我需要削减属性块并创建N个新块。XSLT:在迭代时将节点复制到另一个节点

输入:

<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> 

在此先感谢

回答

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> 
相关问题