2011-01-13 14 views
1

要素の開始文字に基づいてファイルを複数のファイルに分割したいとします。例えば:文字列の最初の文字に基づく分割XMLファイル

<Employees>  
<Employee id="1"> 
<firstname value="Atif"></firstname>   
<lastname value="Bashir"></lastname>   
<age >32</age>   
</Employee>  
<Employee id="2"> 
<firstname value="xyz"></firstname>   
<lastname value="abc"></lastname>   
<age >32</age>   
</Employee>  
<Employee id="3"> 
<firstname value="abc"></firstname>   
<lastname value="none"></lastname>   
<age >32</age>   
</Employee>  
</Employees> 

変換を適用した後、上記のファイルは、2つのファイルに分割しなければならないため、従業員/ FIRSTNAME [@value](グループ全データ)の最初の文字。したがって、上記のケースのための最初のファイルは次のようになります。

a.xml

<Employees>  
<Employee id="1"> 
<firstname value="Atif"></firstname>   
<lastname value="Bashir"></lastname>   
<age >32</age>   
</Employee>  
<Employee id="3"> 
<firstname value="abc"></firstname>   
<lastname value="none"></lastname>   
<age >32</age>   
</Employee>  
</Employees> 

と第二のファイルは次のようになります。XSLTコードがあると何

x.xml

<Employees>  
<Employee id="2"> 
<firstname value="xyz"></firstname>   
<lastname value="abc"></lastname>   
<age >32</age>   
</Employee>  
</Employees>  

この変換を実行しますか?

ありがとうございました!

答えて

3

<xsl:for-each-group select="Employee" 
        group-by="lower-case(substring(firstname,1,1))"> 
    <xsl:result-document href="{current-grouping-key()}.xml"> 
    <xsl:copy-of select="current-group()"/> 
    </xsl:result-document> 
</xsl:for-each-group> 
+0

+1優秀な博士ケイ。私はそれがスクロールしないように少しformatingを追加しました... –

+0

ありがとうマイケル。 – atif

関連する問題