2015-06-21 76 views
-3

我正在使用XSLT 2.0從XMl準備一個平面文件。我的輸入XML是XSLT序列號生成

<city> 
    <family> 
    <parent>A</parent> 
    <child>A1</child> 
    </family> 
    <family> 
    <parent>A</parent> 
    <child>A2</child> 
    </family> 
    <family> 
    <parent>B</parent> 
    <child>B1</child> 
    </family> 
    <family> 
    <parent>B</parent> 
    <child>B2</child> 
    </family> 
    <family> 
    <parent>B</parent> 
    <child>B3</child> 
    </family> 
    <family> 
    <parent>C</parent> 
    <child>C1</child> 
    </family> 


</city> 

Expected Output 
----------------- 
01 A 
02 B 
03 C 

我必須組合父,每個父母在平面文件中有一個條目,它應該有正確的序列號。我無法正確生成序列。

+5

請告訴我們您的'xslt'代碼,以便我們可以幫助您改善它 –

回答

2

假設你使用for-each-group然後輸出和格式化position()應該足夠了:

<xsl:template match="/"> 
     <xsl:for-each-group select="city/family" group-by="parent"> 
      <xsl:value-of select="concat(format-number(position(), '00'), ' ', current-grouping-key(), '&#10;')"/> 
     </xsl:for-each-group> 
    </xsl:template>