2014-05-22 45 views
1

我有一個索引文件,包含的XML文件的列表的過程:在XSLT排序表2.0

<?xml version="1.0" encoding="UTF-8"?> 
<list> 
<part> 
     <numberGroup format="1" start="1"> 
    <entry> 
     <file>04.xml</file> 
      <title>first file</title> 
      <css>stylesheet.css</css> 
    </entry> 
    <entry> 
     <file>05.xml</file> 
      <title>second file</title> 
      <css>stylesheet.css</css> 
    </entry> 
    <entry> 
    <file>06.xml</file> 
      <title>third file</title> 
      <css>stylesheet.css</css> 
     </entry> 
     .... more files 
    </numberGroup> 
    .... more NumberGroups 
    </part> 
    ....more parts 
</list> 

每個文件01.xml等具有一個HTML樣式表,就像這樣:

<table class='wl'> 
<tr class='header'> 
    <td><p>English</p></td> 
    <td><p>French</p></td> 
</tr> 
<tr> 
    <td><p>belly</p></td> 
    <td><p>ventre</p></td> 
</tr> 
<tr> 
    <td><p>leg</p></td> 
    <td><p>jambe</p>/td> 
</tr> 
... etc 
</table> 

我想將所有的表格(在這個例子中是3)合併成一個,所以我得到了一個有競爭力的詞彙表。

到目前爲止,我有這個樣式表:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:template match="/"> 
    <xsl:result-document href="wl.xml"> 
     <xsl:text disable-output-escaping="yes"> 
&lt;!DOCTYPE html&gt; 
     </xsl:text> 
     <html xmlns:epub="http://www.idpf.org/2007/ops" lang="nl" xml:lang="nl"> 
    <head> 
     <title> 
     <xsl:value-of select="./title"/> 
     </title> 
     <xsl:apply-templates select="css"/> 
     </head> 
    <body> 
    <table> 
     <xsl:apply-templates select="//numberGroup[1]/entry"> 
     </xsl:apply-templates> 
    </table> 
    </body> 
    </html> 
    </xsl:result-document> 
    </xsl:template> 
    <xsl:template match="entry"> 
<xsl:apply-templates select="document(file)//table[@class='wl']/tr[not(contains(@class, 'header'))]"/> 
</xsl:template> 
<xsl:template match="tr"> 
    <xsl:copy-of select="."/> 
</xsl:template> 
</xsl:stylesheet> 

根據需要,除了分揀其合併。 如何在第一列按字母順序排列生成的表?

回答

2

更換

<xsl:apply-templates select="//numberGroup[1]/entry"> 
     </xsl:apply-templates> 

<xsl:apply-templates select="document(//numberGroup[1]/entry/file)//table[@class='wl']/tr[not(contains(@class, 'header'))]"> 
    <xsl:sort select="td[1]" data-type="text"/> 
     </xsl:apply-templates> 

,那麼你可以刪除模板entry元素。

+0

不錯!很有幫助。謝謝。 – Erik

+0

和第二個問題:如何向tr添加一個td(第三列),其中包含/ list/part/numberGroup/entry/title? (「第一個文件」等) – Erik

+0

考慮在此問一個新的,單獨的問題。 –