2016-12-16 181 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> 
相關問題