2016-08-26 9 views
0

Saxon 9.7 xslt v3では、スプレッドシートを作成していますが、コンテンツは2つの別々のxsl:for-eachブロックで生成されています。 最初のブロックはツリーの上位にあるノードを選択します。データモデルレベルに関する情報を表示します。 第二のブロックは、データ・レベル・モデルの情報を含むが、以下の出力を生成する、変数およびモデル内容の詳細に行く:複数のfor-eachでのXSLTソート

current result

最初の4行(1 xsl:for-each)がモデルでありますデータモデルの注釈を示すレベル、変数注釈を含む可変レベルの先行する行(第2のxsl:for-each子ノードの選択)。

データモデル情報と第2のxsl:for-eachの可変情報が一緒になるようにデータモデルごとにソートしたいと思います。

これまでのところ、xsl:for-eachにはxsl:sortしか含まれていません。 私が見たいのは何

dataList/ordinal 
dataList/dataListDefault/ordinal 
dataList/dataListDefault/variableList/variableListDefualt/ordinal 
dataList/dataListDefault/variableList/variableListDefualt/annotationList/annotationDefault/ordinal 

によって全体的にソートしたいと思います: wanted result

マイ

<?xml version="1.0" encoding="UTF-8"?> 
<tables> 
    <dataList> 
     <ordinal>1</ordinal> 
     <name>DATA1</name> 
     <label>Data 1</label> 
      <datasetList> 
      <datasetListDefault> 
       <ordinal>1</ordinal> 
       <name>DS1</name> 
       <annotationList> 
        <annotation> Dataset 1</annotation> 
       </annotationList> 
      <variableList> 
       <variableListDefault> 
        <ordinal>1</ordinal> 
        <name>VAR1</name> 
        <label>Variable 1</label> 
        <annotationList> 
         <annotationDefault> 
          <ordinal>2</ordinal> 
          <annotation>This is the 1st variable</annotation> 
         </annotationDefault> 
         <annotationDefault> 
          <ordinal>1</ordinal> 
          <annotation>Variable used for analysis</annotation> 
         </annotationDefault> 
        </annotationList> 
       </variableListDefault> 
       <variableListDefault> 
        <ordinal>2</ordinal> 
        <name>VAR2</name> 
        <label>Variable 2</label> 
        <annotationList> 
         <annotationDefault> 
          <ordinal>1</ordinal> 
          <annotation>This is the 2nd variable</annotation> 
         </annotationDefault>  
        </annotationList> 
       </variableListDefault>     
      </variableList> 
      </datasetListDefault>  
       <datasetListDefault> 
        <ordinal>2</ordinal> 
        <name>DS2</name> 
        <annotationList> 
         <annotation> Dataset 2</annotation> 
        </annotationList> 
        <variableList> 
         <variableListDefault> 
          <ordinal>1</ordinal> 
          <name>VAR1</name> 
          <label>Variable 1</label> 
          <annotationList> 
           <annotationDefault> 
            <ordinal>1</ordinal> 
            <annotation>This is the 1st variable</annotation> 
           </annotationDefault> 
           <annotationDefault> 
            <ordinal>2</ordinal> 
            <annotation>Remove when x</annotation> 
           </annotationDefault> 
          </annotationList> 
         </variableListDefault> 
         <variableListDefault> 
          <ordinal>2</ordinal> 
          <name>VAR2</name> 
          <label>Variable 2</label> 
          <annotationList> 
           <annotationDefault> 
           <ordinal>1</ordinal> 
           <annotation>This is the 2nd variable</annotation> 
           </annotationDefault>  
          </annotationList> 
         </variableListDefault>     
        </variableList> 
       </datasetListDefault> 
      </datasetList> 
    </dataList> 
    <dataList> 
     <ordinal>2</ordinal> 
     <name>DATA2</name> 
     <label>Data 2</label> 
     <datasetList> 
      <datasetListDefault> 
       <ordinal>1</ordinal> 
       <name>DS21</name> 
       <annotationList> 
        <annotation> Dataset 21</annotation> 
       </annotationList> 
       <variableList> 
        <variableListDefault> 
         <ordinal>1</ordinal> 
         <name>VAR1</name> 
         <label>Variable 1</label> 
         <annotationList> 
          <annotationDefault> 
           <ordinal>1</ordinal> 
           <annotation>This is the 1st variable</annotation> 
          </annotationDefault>  
         </annotationList> 
        </variableListDefault> 
        <variableListDefault> 
         <ordinal>2</ordinal> 
         <name>VAR2</name> 
         <label>Variable 2</label> 
         <annotationList> 
          <annotationDefault> 
           <ordinal>1</ordinal> 
           <annotation>This is the 2nd variable</annotation> 
          </annotationDefault>  
         </annotationList> 
        </variableListDefault>     
       </variableList> 
      </datasetListDefault>  
      <datasetListDefault> 
       <ordinal>2</ordinal> 
       <name>DS22</name> 
       <annotationList> 
        <annotation> Dataset 22</annotation> 
       </annotationList> 
       <variableList> 
        <variableListDefault> 
         <ordinal>1</ordinal> 
         <name>VAR1</name> 
         <label>Variable 1</label> 
         <annotationList> 
          <annotationDefault> 
           <ordinal>1</ordinal> 
           <annotation>This is the 1st variable</annotation> 
          </annotationDefault>  
         </annotationList> 
        </variableListDefault> 
        <variableListDefault> 
         <ordinal>2</ordinal> 
         <name>VAR2</name> 
         <label>Variable 2</label> 
         <annotationList> 
          <annotationDefault> 
           <ordinal>1</ordinal> 
           <annotation>This is the 2nd variable</annotation> 
          </annotationDefault>  
         </annotationList> 
        </variableListDefault>     
       </variableList> 
      </datasetListDefault> 
     </datasetList> 
    </dataList>  
</tables> 

XMLとXSLT

<?xml version="1.0" encoding="UTF-8"?> 
<?mso-application progid="Excel.Sheet"?> 
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
    xmlns:o="urn:schemas-microsoft-com:office:office" 
    xmlns:x="urn:schemas-microsoft-com:office:excel" 
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" 
    xmlns:html="http://www.w3.org/TR/REC-html40" > 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

    <xsl:template match="/"> 
     <xsl:processing-instruction name="mso-application">progid="Excel.Sheet"</xsl:processing-instruction> 
     <ss:Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> 

      <xsl:call-template name="document-properties"/> 
      <xsl:call-template name="document-styles"/> 

      <!-- ****************************************************************************************** --> 
      <!-- CREATE THE TABS IN THE WORKBOOK --> 
      <!-- ****************************************************************************************** -->   
      <xsl:call-template name="getData"/> 

      <!-- ****************************************************************************************** --> 

     </ss:Workbook> 
    </xsl:template> 


    <xsl:template name="getData">  

     <ss:Worksheet ss:Name="Data"> 
      <Names> 
       <NamedRange ss:Name="_FilterDatabase" ss:RefersTo="=Data!R1C1:R1C7" ss:Hidden="1"/> 
      </Names> 

      <ss:Table ss:ExpandedRowCount="7000" x:FullColumns="1" x:FullRows="1" >   
       <Column ss:Width="100"/> 
       <Column ss:Width="300"/> 
       <Column ss:Width="100"/> 
       <Column ss:Width="250"/> 
       <Column ss:Width="140"/> 
       <Column ss:Width="140"/>     
       <Column ss:Width="400"/> 

       <Row> 
        <Cell ss:StyleID="sHead"> 
         <Data ss:Type="String">Data Model Name </Data> 
         <NamedCell ss:Name="_FilterDatabase"/> 
        </Cell> 
        <Cell ss:StyleID="sHead"> 
         <Data ss:Type="String">Data Model Label </Data>  
         <NamedCell ss:Name="_FilterDatabase"/> 
        </Cell>      
        <Cell ss:StyleID="sHead"> 
         <Data ss:Type="String">Dataset Name</Data> 
         <NamedCell ss:Name="_FilterDatabase"/> 
        </Cell>  
        <Cell ss:StyleID="sHead"> 
         <Data ss:Type="String">Varaible Label</Data>  
         <NamedCell ss:Name="_FilterDatabase"/> 
        </Cell>  
        <Cell ss:StyleID="sHead"> 
         <Data ss:Type="String">Variable Name</Data>  
         <NamedCell ss:Name="_FilterDatabase"/> 
        </Cell> 
        <Cell ss:StyleID="sHead"> 
         <Data ss:Type="String">Annotation</Data>  
         <NamedCell ss:Name="_FilterDatabase"/> 
        </Cell> 
       </Row>    

       <xsl:for-each select="//datasetListDefault"> 
        <xsl:sort select="../../ordinal"/> 
         <xsl:sort select="ordinal"/>  
        <Row ss:AutoFitHeight="1"> 
         <Cell ss:StyleID="sBody"> 
          <Data ss:Type="String"> 
           <xsl:value-of select="../../name"/> 
          </Data> 
         </Cell> 
         <Cell ss:StyleID="sBody"> 
          <Data ss:Type="String"> 
           <xsl:value-of select="../../label"/> 
          </Data> 
         </Cell>  
         <Cell ss:StyleID="sBody"> 
          <Data ss:Type="String"> 
           <xsl:value-of select="name"/> 
          </Data> 
         </Cell> 
         <Cell ss:StyleID="sBody"> 
          <Data ss:Type="String"></Data> 
         </Cell> 
         <Cell ss:StyleID="sBody"> 
          <Data ss:Type="String"></Data> 
         </Cell> 
         <Cell ss:StyleID="sBody"> 
          <ss:Data ss:Type="String"> 
            <xsl:value-of select="annotationList/annotation"/> 
          </ss:Data> 
         </Cell>       
        </Row>  
       </xsl:for-each> 

       <xsl:for-each select="//variableListDefault"> 
        <xsl:sort select="../../../../ordinal"/> 
        <xsl:sort select="../../ordinal"/>  
        <xsl:sort select="ordinal"/> 
        <xsl:sort select="following-sibling::annotationList/annotationDefault/ordinal"/> 
         <Row ss:AutoFitHeight="1"> 
         <Cell ss:StyleID="sBody"> 
          <Data ss:Type="String"> 
           <xsl:value-of select="../../../../name"/> 
          </Data> 
         </Cell> 
         <Cell ss:StyleID="sBody"> 
          <Data ss:Type="String"> 
           <xsl:value-of select="../../../../label"/> 
          </Data> 
         </Cell>  
         <Cell ss:StyleID="sBody"> 
          <Data ss:Type="String"> 
           <xsl:value-of select="../../name"/> 
          </Data> 
         </Cell> 
         <Cell ss:StyleID="sBody"> 
          <Data ss:Type="String"> 
           <xsl:value-of select="label"/> 
          </Data> 
         </Cell> 
         <Cell ss:StyleID="sBody"> 
          <Data ss:Type="String"> 
           <xsl:value-of select="name"/> 
          </Data> 
         </Cell>   
         <Cell ss:StyleID="sBody"> 
          <ss:Data ss:Type="String"> 
            <xsl:apply-templates select="annotationList/annotationDefault/annotation"/> 
          </ss:Data> 
         </Cell> 
        </Row> 
       </xsl:for-each> 

      </ss:Table> 
      <xsl:call-template name="worksheet-options"/> 

      <AutoFilter x:Range="R1C1:R1C7" xmlns="urn:schemas-microsoft-com:office:excel"/> 
     </ss:Worksheet> 

    </xsl:template> 



    <!-- 
    *************************************GENERAL TEMPLATES************************************************** 
    --> 

    <!-- EXCEL WORKSHEET OPTIONS -->   
    <xsl:template name="worksheet-options"> 
     <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> 
      <PageSetup> 
       <Header x:Margin="0.3"/> 
       <Footer x:Margin="0.3"/> 
       <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/> 
      </PageSetup> 
      <Selected/> 
      <FreezePanes/> 
      <FrozenNoSplit/> 
      <SplitHorizontal>1</SplitHorizontal> 
      <TopRowBottomPane>1</TopRowBottomPane> 
      <ActivePane>2</ActivePane> 
      <Panes> 
       <Pane> 
        <Number>3</Number> 
        <ActiveRow>18</ActiveRow> 
        <ActiveCol>2</ActiveCol> 
       </Pane> 
      </Panes> 
      <ProtectObjects>False</ProtectObjects> 
      <ProtectScenarios>False</ProtectScenarios> 
     </WorksheetOptions> 
    </xsl:template> 

    <!-- EXCEL DOCUMENT PROPERTIES --> 
    <xsl:template name="document-properties"> 
     <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> 
      <Author></Author> 
      <LastAuthor></LastAuthor> 
      <Created>2016-08-24T10:40:32Z</Created> 
      <Company></Company> 
      <Version>14.00</Version> 
     </DocumentProperties> 
     <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> 
      <WindowHeight>14370</WindowHeight> 
      <WindowWidth>27795</WindowWidth> 
      <WindowTopX>480</WindowTopX> 
      <WindowTopY>120</WindowTopY> 
      <ProtectStructure>False</ProtectStructure> 
      <ProtectWindows>False</ProtectWindows> 
     </ExcelWorkbook> 
    </xsl:template> 

    <!-- EXCEL DOCUMENT STYLES --> 
    <xsl:template name="document-styles"> 
     <ss:Styles> 
      <ss:Style ss:ID="Default" ss:Name="Normal"> 
       <ss:Alignment ss:Vertical="Bottom" ss:WrapText="1"/> 
       <ss:Borders/> 
       <ss:Font ss:FontName="Arial" x:Family="Swiss" ss:Size="10" ss:Color="#000000"/> 
       <ss:Interior/> 
       <ss:NumberFormat/> 
       <ss:Protection/> 
      </ss:Style> 
      <ss:Style ss:ID="sHead"> 
       <Alignment ss:Horizontal="Center" ss:Vertical="Top" ss:WrapText="1"/> 
       <ss:Borders> 
        <ss:Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/> 
        <ss:Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/> 
        <ss:Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/> 
        <ss:Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/> 
       </ss:Borders> 
       <Font ss:FontName="Arial" x:Family="Swiss" ss:Size="9" ss:Color="#FFFFFF"/> 
       <ss:Interior ss:Color="#538DD5" ss:Pattern="Solid"/> 
      </ss:Style> 
      <ss:Style ss:ID="sBody"> 
       <Alignment ss:Horizontal="Left" ss:Vertical="Top" ss:WrapText="1"/> 
       <ss:Borders> 
        <ss:Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/> 
        <ss:Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/> 
        <ss:Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/> 
        <ss:Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/> 
       </ss:Borders> 
       <ss:Interior ss:Pattern="Solid"/> 
      </ss:Style> 
     </ss:Styles> 
    </xsl:template> 

</xsl:stylesheet> 

質問/または/のブロックの結果データを/または/の初期処理後に並べ替える方法はありますか?また、より多くの私は成功せず、anaylze-string<xsl:sort select="following-sibling::annotationList/annotationDefault/ordinal"/>でソート を介してこれを渡すために試してみた//variableListDefault/annotationList/annotationDefault/ordinalのための兄弟をソート

。どのソートオプションがこれらの兄弟ノードを個別に処理し、ソートするか?

+1

私は、問題を実証するのに必要な例を減らし、(b)期待される結果をコード**として投稿することをお勧めします。 [mcve]。 –

答えて

2

あなたのxsl:for-eachステートメントはここにネストする必要があります。代わりにこれを行うの

<xsl:for-each select="//datasetListDefault"> 
    <xsl:sort select="../../ordinal"/> 
    <xsl:sort select="ordinal"/>  
    <Row ss:AutoFitHeight="1"> 
      <!-- snip -->   
    </Row>  
</xsl:for-each> 

<xsl:for-each select="//variableListDefault"> 
    <xsl:sort select="../../../../ordinal"/> 
    <xsl:sort select="../../ordinal"/>  
    <xsl:sort select="ordinal"/> 
    <Row ss:AutoFitHeight="1"> 
      <!-- snip -->   
    </Row>  
</xsl:for-each> 

これを行う....

<xsl:for-each select="//datasetListDefault"> 
    <xsl:sort select="../../ordinal"/> 
    <xsl:sort select="ordinal"/>  
    <Row ss:AutoFitHeight="1"> 
     <!-- snip -->   
    </Row>  

    <xsl:for-each select=".//variableListDefault"> 
     <xsl:sort select="../../../../ordinal"/> 
     <xsl:sort select="../../ordinal"/>  
     <xsl:sort select="ordinal"/> 
     <Row ss:AutoFitHeight="1"> 
      <!-- snip -->   
     </Row>  
    </xsl:for-each> 
</xsl:for-each> 

.//variableListDefaultの使用は、それが現在のdatasetListDefaultノードの子孫のみを選択します。 (私は<xsl:for-each select="variableList/variableListDefault">をやっていると思います)。

+0

ブリリアント、ありがとうTim。それはまさに私が後にしたものです。 – Huw