2016-12-16 11 views
0

現在このタイプのリクエストがあります。問題は、既存のコードで1つの属性ブロックしか管理できないことです。私は属性ブロックをカットし、N個の新しいブロックを作成する必要があります。XSLT:反復中にノードを別のノードにコピー

入力:

<Request> 
<Attributes> 
    <Attribute> 
     <Complimentary> 
      Test1 
     </Complimentary> 
    </Attribute> 
    <Attribute> 
     <Complimentary> 
      Test2 
     </Complimentary> 
    </Attribute> 
    <Attribute> 
     <Complimentary> 
      TestN 
     </Complimentary> 
    </Attribute> 
</Attributes> 
</Request> 

出力:事前

答えて

1

<Request> 
    <Attributes> 
     <Attribute> 
      <Complimentary> 
       Test1 
      </Complimentary> 
     </Attribute> 
    </Attributes> 
    <Attributes> 
     <Attribute> 
      <Complimentary> 
       Test2 
      </Complimentary> 
     </Attribute> 
    </Attributes> 
    <Attributes> 
     <Attribute> 
      <Complimentary> 
       TestN 
      </Complimentary> 
     </Attribute> 
    </Attributes> 
</Request> 

おかげで、私はこれを正しく読めば、あなたがしたい:

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> 
関連する問題