2017-10-16 5 views
0

다음 중첩 된 요소가있는 XML이 있습니다. 이 XML을 플랫 계층 구조로 변환하는 데 도움이 필요합니다.XSLT, XML : 그룹화 된 블록을 평면 계층으로 분리하는 방법은 무엇입니까?

당신은뿐만 아니라이 문제를 살펴 싶습니다 수 있습니다 : 귀하의 지원에 미리 XSLT, XML: Grouping by attribute value

감사합니다. 토마스

원본 XML :

<transaction> 
    <records type="1" > 
     <record type="1" > 
     <field number="1" > 
      <item >223</item> 
     </field> 
     </record> 
    </records> 

    <records type="14" > 
     <record type="14" > 
     <field number="1" > 
      <item >777</item> 
     </field> 
     </record> 

     <record type="14" > 
     <field number="1" > 
      <item >555</item> 
     </field> 
     </record> 
    </records> 

    <record type="200" > 
    <field number="1" > 
     <item>546</item> 
    </field> 
    </record> 

    <record type="201" > 
    <field number="1" > 
     <item>123</item> 
    </field> 
    </record> 
</transaction> 

대상 XML :

<transaction>  
    <record type="1" > 
    <field number="1" > 
     <item >223</item> 
    </field> 
    </record> 

    <record type="14" > 
    <field number="1" > 
     <item >777</item> 
    </field> 
    </record> 

    <record type="14" > 
    <field number="1" > 
     <item >555</item> 
    </field> 
    </record> 

    <record type="200" > 
    <field number="1" > 
     <item>546</item> 
    </field> 
    </record> 

    <record type="201" > 
    <field number="1" > 
     <item>123</item> 
    </field> 
    </record> 
</transaction> 
+0

지금까지 무엇을 얻었습니까? – Steve

+0

나는 팀의 대답으로부터 XLST를 가지고있다 : https://stackoverflow.com/questions/46693291/xslt-xml-grouping-by-attribute-value – ThomasMuller

+0

@ThomasMuller는 정반대의 것을 시도하지 않습니까? – kumesana

답변

1

이 시도 :

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:template match="/"> 
     <xsl:text>&#x0A;</xsl:text> 
     <transaction> 
      <xsl:text>&#x0A;</xsl:text> 
      <xsl:for-each select="//record"> 
       <xsl:copy-of select="." /> 
       <xsl:text>&#x0A;</xsl:text> 
      </xsl:for-each> 
      <xsl:text>&#x0A;</xsl:text> 
     </transaction> 
    </xsl:template> 

</xsl:stylesheet> 

<xsl:text> 태그 출력 XML의 형식의 일부를 보존하려면 그러나 당신이 그것에 관심이 있는지 나는 모른다. 그렇지 않으면 삭제하십시오.

for-each을 사용하여 입력 XML에서 요소를 찾습니다. select 속성의 시작 부분에있는 //은 현재 레벨뿐만 아니라 문서 내의 모든 위치와 일치 할 수 있음을 의미합니다.

그러면 간단히 copy-of을 사용하여 for-each에있는 노드 전체를 삽입합니다.

+0

안녕 스티브, 훌륭한 직장 내 친구. 많은 감사합니다. – ThomasMuller