2012-10-31 5 views
1

저는 XSLT의 기본 사항을 잘 알고 있지만 이상한 상황에 처했습니다. 알아낼 수 없습니다. 이 일이 너무 오래되어 사과 드리지만 제공 할 수있는 도움에 정말 감사드립니다.여러 요소로 정렬

나는 당신이 연결을 한 후 이순신 종류의 Level_5에게

XML unsorted: 
<Root att="x"> 
    <Level_1 Name="NEW Level">  
    <Level_2>  
     <Level_3 Name="nameLvl_3">   
     <Level_4>  
      <Level_5 Name="aa"> 
      <Brand> 
       <Value Name="Text" Value="1" /> 
      </Brand>    
     <Docs> 
       <Value Name="Pro" Value="2" /> 
       <Value Name="Numeric" Value="0.05" /> 
      </Docs>    
      </Level_5>    
      <Level_5 Name="aa">    
      <Text> 
       <Val Id="1"/> 
      </Text> 
      </Level_5> 
      <Level_5 Name="aa"> 
      <Brand> 
       <Value Name="Text" Value="2" /> 
       <Value Name="Number" Value="1" /> 
       <Value Name="Long" Value="3" /> 
      </Brand> 
      </Level_5> 
     </Level_4> 
     </Level_3> 
    </Level_2>  
    </Level_1> 
</Root> 

당신이해야 있도록 정렬 된 브랜드/가치/@ 이름과 문서/가치/@ 이름의 연결을 기반으로, Level_5 노드를 정렬하려면 ""LongNumberText는 TextNumericPro 과 예상 출력은 다음과 같습니다

<Root att="x"> 
    <level_1 Name="NEW Level">  
    <level_2>  
     <Level_3 Name="nameLvl_3">   
     <Level_4> 
      <Level_5 Name="aa">    
      <Text> 
       <Val Id="1"/> 
      </Text> 
      </Level_5> 
      <Level_5 Name="aa"> 
      <Brand> 
      <Value Name="Long" Value="3" /> 
     <Value Name="Number" Value="1" /> 
       <Value Name="Text" Value="2" />    
      </Brand> 
      </Level_5> 
      <Level_5 Name="aa"> 
      <Brand> 
       <Value Name="Text" Value="1" /> 
      </Brand>    
    <Docs>   
       <Value Name="Numeric" Value="0.05" /> 
       <Value Name="Pro" Value="2" /> 
      </Docs>    
      </Level_5> 
     </Level_4> 
     </Level_3> 
    </Level_2>  
    </Level_1> 
</Root> 

내가 할 수있는 유일한 종류의 난의 나머지 부분을 연결하는 방법을 어떤 생각이없는/브랜드/가치/@ 이름의 첫 번째 요소에 의해서가 아니라 브랜드 및 문서 도구 내부의 속성입니다.이 코드는 NG :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output omit-xml-declaration="yes" indent="yes"/> 
    <xsl:strip-space elements="*"/> 

    <xsl:template match="node()|@*"> 
    <xsl:copy> 
     <xsl:apply-templates select="node()|@*"/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="Level_3/Level_4/Level_5/Brand|Docs"> 
    <xsl:copy> 
     <xsl:apply-templates> 
     <xsl:sort select="@Name" data-type="text"/> 
     <xsl:sort select="@Value" data-type="text"/> 
     </xsl:apply-templates> 
    </xsl:copy> 
    </xsl:template> 

    <!--             --> 
    <xsl:template match="Level_2/Level_3/Level_4"> 
    <xsl:copy> 
     <xsl:apply-templates select="Level_5"> 
     <xsl:sort select="Brand|Docs/Value/@Name" data-type="text"/> 
     </xsl:apply-templates> 
    </xsl:copy> 
    </xsl:template> 

</xsl:stylesheet> 

하지만 난 그것을 그저 안녕 브랜드의 내부 또는 문서가 어떤 도움을 기쁘게 첫 번째 요소

답변

0

이하는 XPath 1.0 표현이 할 수있는 현명한 방법이 될,하지만 난 아니에요 수 있습니다 하나를보고. 보다 간단한 방법은 두 단계로 데이터를 처리하는 것입니다.

처음에는 거의 아이덴티티 변환을 수행하는 스타일 시트를 작성합니다. 입력은 그대로 출력에 다시 쓰여지지만 각 Level_5 요소에는 모두 정렬하여 생성하는 정렬 키가있는 속성을 추가합니다 적절한 아이를 make-sort-key 모드로 지정합니다.

다른 스타일 시트를 작성하고 sort-key 속성을 사용하여 정렬을 제어하십시오 (원하지 않으면 다시 놓습니다).

다른 주제 : 일치 패턴 Level_3/Level_4/Level_5/Brand | DocsLevel_3/Level_4/Level_5/Brand | Level_3/Level_4/Level_5/Docs과 같지 않습니다. 후자가 의미하는 경우 다른 일치 패턴이 필요합니다.

+0

이미 두 단계로 진행하지만 한 단계로 제한됩니다. – user1789798