2014-05-01 3 views
0

xslt를 사용하여 루트 아래에서 몇 가지 특성을 가진 xml 파일을 변환해야합니다. 단일 루트 발생에 대해 사용할 수 있습니다. 그러나 입력 된 xml에는 여러 레코드가 포함됩니다 (서브 노드는 서브 노드로 & 발생). 다른 값들) 루핑을 추가하는 방법. 그래서 첫번째 루트의 파싱을 완료 한 후에 그것의 다음 accourence로 간다. 다음은 입력 XML은XSLT 루핑을 사용하여 xml에서 xml로 변환

입력 XML

<Information> 
    <Name>Joe</Name> 
    <DOB>01012014</DOB> 
</Information> 
<Information> 
    <Name>Mark</Name> 
    <DOB>12012012</DOB> 
</Information> 

XSLT :

<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" omit-xml-declaration="yes"/> 

    <xsl:template match="/"> 
     <xsl:element name="Information"> 
      <xsl:apply-templates select="Information/Name"/> 
      <xsl:apply-templates select="Information/DOB"/> 
     </xsl:element> 
    </xsl:template> 

    <xsl:template match="Information/Name"> 
     <xsl:element name="Name"> 
      <xsl:value-of select="."/> 
     </xsl:element> 
    </xsl:template> 

    <xsl:template match="Information/DOB"> 
     <xsl:element name="DOB"> 
      <xsl:value-of select="."/> 
     </xsl:element> 
    </xsl:template> 

</xsl:stylesheet> 

는 출력 : 기본적으로 먼저 이름 및 프로세스 루트 노드 정보를 모두 DOB의 순서를 변경해야 할

<Information> 
    <DOB>01012014</DOB> 
    <Name>Joe</Name> 
</Information> 
<Information> 
    <DOB>12012012</DOB> 
    <Name>Mark</Name> 
</Information> 

도움을 주시면 감사하겠습니다.

+0

요소를 래핑하는 루트 노드를 추가하려면 입력 소스를 사전 처리해야합니다. 이는 형식이 잘못되어 XSLT 입력으로 허용되지 않기 때문입니다. – helderdarocha

+0

엔터티 참조를 사용하여 XML 조각을 포함하는 "래퍼"XML 파일을 만들 수도 있습니다. http://stackoverflow.com/a/5127928/14419 –

+0

@MadsHansen 이것은 흥미로운 아이디어이지만 처리 할 문서 래퍼? –

답변

2

내 입력 XML은 여러 최상위 요소가 포함되어있는 경우 다음 더 이상 XML되지 않은 여러 레코드

포함됩니다.