在XSLT 2.0中对表格进行排序

埃里克

我有一个索引文件,其中包含要处理的xml文件列表:

<?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>

除排序外,它可以根据需要合并。如何在第一列上按字母顺序对生成的表进行排序?

马丁·洪恩(Martin Honnen)

代替

<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元素模板

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章