2014-03-28 115 views
0

我想對多個屬性/元素進行排序。對@status和cci進行排序:ArtifactLocation可以正常工作,但是相同的技術不會對cci:ArtifactLocation/@ line屬性進行排序。我使用XMLSpy 2014和saxon9he.jar進行測試,結果相同。你知道什麼可能是錯的嗎?對多個屬性/元素進行XSLT排序

  1. 輸入XML如下:

    <?xml version="1.0" encoding="UTF-8"?> 
    <ValidatorResult xmlns="http://www.oracle.com/soa/fp/governance/auditor"> 
    <Header> 
        <SourceDirectory>file:/ade/ranchand_dte8052/oracle/work/CodeComplianceInspectorLrg/testData/AIADemo/</SourceDirectory> 
        <SourceDirectoryMask>${inputDir}</SourceDirectoryMask> 
        <DisplayLabel>AIADemo</DisplayLabel> 
        <AssertionCatalog>AssertionCatalog-WS-I_12.1.3.0.0.xml</AssertionCatalog> 
        <PoliciesFile>Policies-WS-I_12.1.3.0.0.xml</PoliciesFile> 
        <Policy>Reusability Standards</Policy> 
        <DateTime>AIA DEMO DATE OF EXECUTION</DateTime> 
        <Version>AIA Build</Version> 
    </Header> 
    <PolicyResult name="Reusability Standards" total="1" failed="1" success="0" notExecuted="0"> 
        <AssertionResult priority="2" name="NoLocalSchemasInBPELCheck" category="Reusability Standards" failed="32" total="119" success="87"> 
        <Message>BPEL Process folder should not contain any schema files. All Utility schema should be accessed from a web server.</Message> 
        <Result>Fail</Result> 
        <ExecutionDetails> 
         <Composite name="SamplesSyncCustomerPartyListEBF" version="1.0" success="2" failed="1"> 
        <Execution status="1"> 
          <ArtifactLocation>${inputDir}3.xTestData/EBFTargetNameSpacesCheck/SamplesSyncCustomerPartyListEBF/</ArtifactLocation> 
          </Execution> 
          <Execution status="0"> 
          <ArtifactLocation>${inputDir}3.xTestData/AIAServiceConfigFileForEBFExistsCheck/SamplesSyncCustomerPartyListEBF/</ArtifactLocation> 
          </Execution> 
          <Execution status="1"> 
          <ArtifactLocation>${inputDir}3.xTestData/wsdlRuntimeLocationExistForPlinkInEBFCheck/SamplesSyncCustomerPartyListEBF/</ArtifactLocation> 
          </Execution> 
         </Composite> 
         <Composite name="AIADemoCreateShipmentRequestBatchProvABCSImpl" version="1.0" success="1" failed="0"> 
          <Execution status="1"> 
          <ArtifactLocation>${inputDir}samples/AIADemo/ProviderABCS/AIADemoCreateShipmentRequestBatchProvABCSImpl/</ArtifactLocation> 
          </Execution> 
         </Composite> 
         <Composite name="MatchAccountSiebelReqABCSImpl" version="1.0" success="1" failed="0"> 
          <Execution status="1"> 
          <ArtifactLocation>${inputDir}Siebel/RequesterABCS/MatchAccountSiebelReqABCSImpl/</ArtifactLocation> 
          </Execution> 
         </Composite> 
         <Composite name="CheckATPSalesOrderSiebelFusionDOOABF" version="1.0" success="9" failed="2"> 
          <Execution status="1"> 
          <ArtifactLocation line="400" col="46">${inputDir}ApplicationBusinessFlow/CheckATPSalesOrderSiebelFusionDOOABF/CheckATPSalesOrderSiebelFusionDOOABF.bpel</ArtifactLocation> 
          </Execution> 
        <Execution status="1"> 
        <ArtifactLocation line="131" col="46">${inputDir}ApplicationBusinessFlow/CheckATPSalesOrderSiebelFusionDOOABF/CheckATPSalesOrderSiebelFusionDOOABF.bpel</ArtifactLocation> 
          </Execution> 
          <Execution status="1"> 
          <ArtifactLocation line="159" col="54">${inputDir}ApplicationBusinessFlow/CheckATPSalesOrderSiebelFusionDOOABF/CheckATPSalesOrderSiebelFusionDOOABF.bpel</ArtifactLocation> 
          </Execution> 
          <Execution status="1"> 
          <ArtifactLocation line="186" col="45">${inputDir}ApplicationBusinessFlow/CheckATPSalesOrderSiebelFusionDOOABF/CheckATPSalesOrderSiebelFusionDOOABF.bpel</ArtifactLocation> 
          </Execution> 
          <Execution status="1"> 
          <ArtifactLocation line="221" col="33">${inputDir}ApplicationBusinessFlow/CheckATPSalesOrderSiebelFusionDOOABF/CheckATPSalesOrderSiebelFusionDOOABF.bpel</ArtifactLocation> 
          </Execution> 
          <Execution status="0"> 
          <ArtifactLocation line="238" col="82">${inputDir}ApplicationBusinessFlow/CheckATPSalesOrderSiebelFusionDOOABF/CheckATPSalesOrderSiebelFusionDOOABF.bpel</ArtifactLocation> 
          </Execution> 
          <Execution status="1"> 
          <ArtifactLocation line="249" col="43">${inputDir}ApplicationBusinessFlow/CheckATPSalesOrderSiebelFusionDOOABF/CheckATPSalesOrderSiebelFusionDOOABF.bpel</ArtifactLocation> 
          </Execution> 
          <Execution status="1"> 
          <ArtifactLocation line="264" col="56">${inputDir}ApplicationBusinessFlow/CheckATPSalesOrderSiebelFusionDOOABF/CheckATPSalesOrderSiebelFusionDOOABF.bpel</ArtifactLocation> 
          </Execution> 
          <Execution status="0"> 
          <ArtifactLocation line="345" col="50">${inputDir}ApplicationBusinessFlow/CheckATPSalesOrderSiebelFusionDOOABF/CheckATPSalesOrderSiebelFusionDOOABF.bpel</ArtifactLocation> 
          </Execution> 
          <Execution status="1"> 
          <ArtifactLocation line="376" col="39">${inputDir}ApplicationBusinessFlow/CheckATPSalesOrderSiebelFusionDOOABF/CheckATPSalesOrderSiebelFusionDOOABF.bpel</ArtifactLocation> 
          </Execution> 
          <Execution status="1"> 
          <ArtifactLocation line="104" col="99">${inputDir}ApplicationBusinessFlow/CheckATPSalesOrderSiebelFusionDOOABF/CheckATPSalesOrderSiebelFusionDOOABF.bpel</ArtifactLocation> 
          </Execution> 
         </Composite> 
        </ExecutionDetails> 
        </AssertionResult> 
    </PolicyResult> 
    

XSLT轉換如下:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cci="http://www.oracle.com/soa/fp/governance/auditor" exclude-result-prefixes="cci"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="cci:ExecutionDetails"> 
     <xsl:copy> 
      <xsl:apply-templates select="cci:Composite"> 
       <xsl:sort select="@name" lang="en" data-type="text" order="ascending"/>    
      </xsl:apply-templates>   
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="cci:Composite"> 
     <xsl:copy> 
      <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute> 
      <xsl:attribute name="version"><xsl:value-of select="@version"/></xsl:attribute> 
      <xsl:attribute name="success"><xsl:value-of select="@success"/></xsl:attribute> 
      <xsl:attribute name="failed"><xsl:value-of select="@failed"/></xsl:attribute> 
      <xsl:choose> 
       <xsl:when test="not(cci:Composite/cci:ArtifactLocation/@line)"> 
        <xsl:apply-templates select="cci:Execution"> 
         <xsl:sort select="@status" data-type="number"/>      
         <xsl:sort select="cci:ArtifactLocation" lang="en" case-order="lower-first" order="ascending"/>      
        </xsl:apply-templates> 
       </xsl:when> 
       <xsl:otherwise>     
        <xsl:apply-templates select="cci:Execution"> 
         <xsl:sort select="@status" data-type="number"/> 
         <xsl:sort select="cci:ArtifactLocation" lang="en" case-order="lower-first" order="ascending"/> 
         <xsl:sort select="cci:ArtifactLocation/@line" data-type="number" order="ascending"/>            
        </xsl:apply-templates> 
       </xsl:otherwise> 
      </xsl:choose> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="cci:Execution"> 
     <xsl:copy> 
      <xsl:attribute name="status"><xsl:value-of select="@status"/></xsl:attribute>    
      <xsl:apply-templates select="cci:ArtifactLocation"/>   
     </xsl:copy>  
    </xsl:template> 
    <xsl:template match="cci:ArtifactLocation"> 
     <xsl:copy-of select="."/> 
    </xsl:template> 
</xsl:stylesheet> 

對於公衆的利益,這裏的答案到這個問題:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cci="http://www.oracle.com/soa/fp/governance/auditor" exclude-result-prefixes="cci"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="cci:ExecutionDetails"> 
     <xsl:copy> 
      <xsl:apply-templates select="cci:Composite"> 
       <xsl:sort select="@name" lang="en" data-type="text" order="ascending"/> 
      </xsl:apply-templates> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="cci:Composite"> 
     <xsl:copy> 
      <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute> 
      <xsl:attribute name="version"><xsl:value-of select="@version"/></xsl:attribute> 
      <xsl:attribute name="success"><xsl:value-of select="@success"/></xsl:attribute> 
      <xsl:attribute name="failed"><xsl:value-of select="@failed"/></xsl:attribute> 
      <xsl:apply-templates select="cci:Execution"> 
       <xsl:sort select="@status" data-type="number"/> 
       <xsl:sort select="cci:ArtifactLocation" lang="en" case-order="lower-first" order="ascending"/> 
       <xsl:sort select="cci:ArtifactLocation/@line" data-type="number" order="ascending"/> 
      </xsl:apply-templates> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="cci:Execution"> 
     <xsl:copy> 
      <xsl:attribute name="status"><xsl:value-of select="@status"/></xsl:attribute> 
      <xsl:apply-templates select="cci:ArtifactLocation"/> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="cci:ArtifactLocation"> 
     <xsl:copy-of select="."/> 
    </xsl:template> 
</xsl:stylesheet> 

回答

0

AFAICT,在測試:

<xsl:when test="not(cci:Composite/cci:ArtifactLocation/@line)"> 

將始終返回true,因爲這是從cci:Composite的背景下完成的,因此,(相對)路徑cci:Composite/cci:ArtifactLocation/@line選擇什麼。所以你畢竟沒有真正排序cci:ArtifactLocation/@line

+0

有關如何改進的建議? – vg600

+0

@ vg600你爲什麼需要這個條件?如果該屬性不存在,排序將不會執行任何操作。 –

+0

你是對的。刪除了條件並開始工作。感謝您的幫助。 – vg600

相關問題