xslt 1.0-col结束标记未被调用



我有XML文档的以下部分。当我在这个XML文档上运行xslt时,col类。。。colgroup内部被调用,colgroup被调用,但col类的结束标记没有被调用。请让我知道如何关闭col课堂。。。最后一段代码包含我的xml html输出。

<table frame="all" width="100%">
        <tgroup cols="2">
            <colspec colnum="1" colname="col1" colwidth="18%"/>
            <colspec colnum="2" colname="col2" colwidth="82%"/>
            <thead>
                <row>
                    <entry namest="col1" nameend="col2">
                        <para>A timeline of British Virgin Islands company law</para>
                    </entry>
                </row>
            </thead>
            <tbody>
                <row>
                    <entry>
                        <para>1884</para>
                    </entry>
                    <entry>
                        <para>Companies Act passed into law.</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>1984</para>
                    </entry>
                    <entry>
                        <para>International Business Companies Act passed into law.</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>2004</para>
                    </entry>
                    <entry>
                        <para>BVI Business Companies Act passed into law, coming into force on 1 January 2005.</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>2005</para>
                    </entry>
                    <entry>
                        <para>All three corporate statutes exist in parallel and it is possible to incorporate companies under any of them.</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>2006</para>
                    </entry>
                    <entry>
                        <para>Incorporation provisions in the International Business Companies Act and the Companies Act are repealed on 31 December 2005; the Acts remain in force but new companies may only be incorporated under the BVI Business Companies Act.</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>2007</para>
                    </entry>
                    <entry>
                        <para>International Business Companies Act repealed on 31 December 2006. Transitional provisions come into effect for companies incorporated under that act.</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>2009</para>
                    </entry>
                    <entry>
                        <para>Companies Act repealed on 31 December 2008. Transitional provisions come into effect for companies incorporated under that Act.</para>
                    </entry>
                </row>
            </tbody>
        </tgroup>
    </table>

下面是我的xslt。

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:ntw="Number2Word.uri" 
                exclude-result-prefixes="ntw">
  <xsl:variable name="ThisDocument" select="document('')"/>
  <xsl:template match="/">
    <html>
      <head>
        <meta http-equiv="Content-Type" 
              content="text/html; charset=UTF-8"/>
        <title>
          <xsl:value-of select="chapter/title"/>
        </title>
        <link rel="stylesheet" href="er:#css" type="text/css"/>
      </head>
      <body>
        <xsl:apply-templates/>
        <hr/>
        <section class="tr_footnotes">
          <xsl:apply-templates select="//footnote" 
                               mode="footnote"/>
        </section>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="chapter">
    <section>
      <div class="chapter">
        <a name="BVI-CH-{@num}"/>
        <xsl:variable name="cnum">
          <xsl:choose>
            <xsl:when test="starts-with(@num,'0')">
              <xsl:value-of select="substring-after(@num,'0')"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="@num"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <div class="chapter-title">
          <span class="chapter-num">
            <xsl:value-of select="concat('Chapter ',$cnum,' ')"/>
          </span>
          <xsl:apply-templates select="title"/>
        </div>                          
        <xsl:apply-templates select="child::node()[not(self::title)]"/>
      </div>
    </section>
  </xsl:template>
  <xsl:template match="chapter/para">
    <div class="para align-right">
      <span class="format-smallcaps">Para</span>.
    </div>
  </xsl:template>
  <!-- Index templates -->
  <xsl:template name="toc" match="chapter/toc">
    <div class="toc">
      <xsl:call-template name="toc-part"/>
    </div>
  </xsl:template>
  <xsl:template name="toc-part" match="chapter/toc/toc-part">
    <div class="toc-part">
      <xsl:call-template name="toc-div"/>
    </div>
  </xsl:template>
  <xsl:template name="toc-div" match="chapter/toc/toc-part/toc-div">
    <table class="toc-div">
      <tbody>
        <xsl:for-each select="current()/toc-part/toc-div/*">
          <xsl:call-template name="toc-item"/>
        </xsl:for-each>
      </tbody>
    </table>
  </xsl:template>
  <xsl:template name="toc-item" match="chapter/toc/toc-part/toc-div/toc-item">
    <xsl:variable name="tocpg">
      <xsl:value-of select="concat('#P',current()/toc-pg/text())"/>
    </xsl:variable>
    <xsl:variable name="tocpgtag" select="translate($tocpg,'.', '-')"/>
    <xsl:variable name="chapternumber">
      <!-- Get num attribute of parent node -->
      <xsl:value-of select="ancestor::chapter[1]/@num"/>
    </xsl:variable>
    <xsl:variable name="itemlevel">
      <xsl:value-of select="$ThisDocument//ntw:nums[@num=$chapternumber]/@word"/>
    </xsl:variable>
    <xsl:variable name="tocitemlevel">
      <xsl:value-of select="concat('toc-item-', $itemlevel,'-level')"/>
    </xsl:variable>
    <table class="{$tocitemlevel}">
      <tbody>
        <tr>
          <td class="toc-item-num">
            <xsl:value-of select="current()/@num"/>
          </td>
          <td class="toc-title">
            <xsl:value-of select="current()/toc-title"/>
          </td>
          <td class="toc-pg">
            <a href="{$tocpgtag}">
              <xsl:value-of select="current()/toc-pg"/>
            </a>
          </td>
        </tr>
      </tbody>
    </table>
  </xsl:template>
  <!-- Index Templates Complete -->
  <!-- Paragraph templates -->
  <xsl:template name="section" match="section">
    <!-- Variables-->
    <xsl:variable name="classname">
      <!--Get name attribute of current node -->
      <xsl:value-of select="concat('section-',@level)"/>
    </xsl:variable>
    <xsl:variable name="chapternumber">
      <!-- Get num attribute of parent node -->
      <xsl:value-of select="ancestor::chapter[1]/@num"/>
    </xsl:variable>
    <xsl:variable name="sectnum">
      <xsl:number level="any" count="section" format="1"/>
    </xsl:variable>
    <!--Create a string variable by concat string method  -->
    <xsl:variable name="sectionname">
      <xsl:value-of select="concat('CH-',$chapternumber,'-SEC-0', $sectnum)"/>
    </xsl:variable>
    <!-- Template Content  -->
    <div class="{$classname}">
      <a name="{$sectionname}"> </a>
      <div class="section-title">
        <span class="section-num">
          <xsl:value-of select="@num"/>
        </span>
        <xsl:apply-templates select="title"/>
      </div>
      <xsl:apply-templates select="child::node()[not(self::title)]"/>
    </div>
  </xsl:template>
  <xsl:template name="para" match="section/para">
    <div class="para">
      <xsl:apply-templates select="phrase"/>
      <span class="phrase">
        <xsl:value-of select="current()/phrase"/>
      </span>
      <xsl:apply-templates select="child::node()[not(self::phrase)]"/>
    </div>

  </xsl:template>
  <xsl:template name="phrase" match="phrase">
    <xsl:variable name="phrase">
      <xsl:value-of select="concat('P',text())"/>
    </xsl:variable>
    <xsl:variable name="newphrase" select="translate($phrase,'.','-')"/>
    <a>
      <xsl:attribute name="name"><xsl:value-of select="$newphrase"></xsl:value-of></xsl:attribute>
    </a>
  </xsl:template>


  <!-- Table Templates  -->
  <xsl:template name="table" match="table">
    <table style="frame-{current()/@frame} width-{translate(current()/@width,'%','')}">
      <xsl:apply-templates/>
    </table>
  </xsl:template>

  <xsl:template match="tgroup">
    <colgroup>
      <xsl:apply-templates select=".//colspec"/>
    </colgroup>
    <xsl:apply-templates select="child::node()[not(self::colspec)]"/>

  </xsl:template>       
  <xsl:template name="tbody" match="tgroup/tbody">
    <tbody>
      <xsl:for-each select="current()/row">
        <xsl:call-template name="row"/>
      </xsl:for-each>
    </tbody>
  </xsl:template>
  <xsl:template name="thead" match="tgroup/thead">
    <xsl:for-each select="current()/row"><thead>

      <tr>
        <xsl:for-each select="current()/entry">
          <xsl:call-template name="headentry"/>
        </xsl:for-each>
      </tr>
    </thead>
    </xsl:for-each>
  </xsl:template>
  <xsl:template name="colspec" match="colspec">
    <col class="colnum-{current()/@colnum} colname-{current()/@colname} colwidth-{translate(current()/@colwidth,'%','')}"></col>
  </xsl:template>
  <xsl:template name="row" match="tbody/row">
    <tr>
      <xsl:for-each select="current()/entry">
        <xsl:call-template name="entry"/>
      </xsl:for-each>
    </tr>
  </xsl:template>
  <xsl:template name="entry" match="entry">
    <xsl:variable name="count">
      <xsl:value-of select="count(preceding-sibling::* | following-sibling::*)"/>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="$count &lt; 2">
        <xsl:if test="position()=1">
          <td>
            <div class="para align-center">
              <xsl:value-of select="para[position()=1]"/>
            </div>
          </td>
          <td>
            <div class="para">
              <xsl:value-of select="following-sibling::node()"/>
            </div>
          </td>
        </xsl:if>
      </xsl:when>
      <xsl:when test="$count &gt; 1">
        <td>
          <div class="para">
            <xsl:apply-templates/>
          </div>
        </td>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="headentry">
    <th>
      <xsl:if test="translate(current()/@namest,'col','') != translate(current()/@nameend,'col','')">
        <xsl:variable name="colspan">
          <xsl:value-of select="translate(current()/@nameend,'col','') - translate(current()/@namest,'col','') + 1"/>
        </xsl:variable>
        <xsl:attribute name="colspan"><xsl:value-of select="$colspan"></xsl:value-of></xsl:attribute>
      </xsl:if>
      <div class="para">
        <xsl:value-of select="current()/para/text()"/>
      </div>
    </th>
  </xsl:template>
  <!-- Table Templates complete  -->

  <!--List templates -->
  <xsl:template name="orderedlist" match="orderedlist">
    <ol class="orderedlist">
      <xsl:apply-templates/>
    </ol>
  </xsl:template>
  <xsl:template name="orderitem" match="orderlist/item">
    <li class="item">
      <xsl:apply-templates/>
    </li>
  </xsl:template>
  <xsl:template name="orderitempara" match="item/para">
    <xsl:variable name="itemnumber">
      <xsl:value-of select="parent::item[1]/@num"/>
    </xsl:variable>
    <li class="item">
      <div class="para">
        <span class="item-num">
          <xsl:value-of select="parent::item[1]/@num"/>
        </span>
        <xsl:apply-templates/>
      </div>
    </li>
  </xsl:template>
  <!--List templates Complete -->
  <!-- Paragraph templates Complete -->
  <!-- Footnote Templates-->
  <xsl:template match="footnote">
    <sup>
      <a>
        <xsl:attribute name="name"><xsl:text>footnoteref</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
        <xsl:attribute name="href"><xsl:text>#footnote</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
        <xsl:attribute name="class"><xsl:text>tr_ftn</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
        <xsl:number level="any" count="footnote" format="1"/>
      </a>
    </sup>
  </xsl:template>
  <xsl:template match="footnote" mode="footnote">
    <sup>
      <li style="list-style-type:none;indent:0">
        <a>
          <xsl:attribute name="name"><xsl:text>footnote</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
          <xsl:attribute name="href"><xsl:text>#footnoteref</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
          <xsl:attribute name="class"><xsl:text>tr_ftn</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
          <xsl:number level="any" count="footnote" format="1"/>
        </a>
        <xsl:text> </xsl:text>
        <xsl:apply-templates/>
      </li>
    </sup>
  </xsl:template>
  <xsl:template match="footnote/para/uri">
    <xsl:variable name="url1">
      <xsl:value-of select="translate(@href, '&#x003C;','')" />
    </xsl:variable>
    <xsl:variable name="url2">
      <xsl:value-of select="translate($url1, '&#x003E;','')" />
    </xsl:variable>
    <a href="{$url2}">
      <xsl:value-of select="." />
    </a>

  </xsl:template>
  <!-- Footnote Templates Complete -->
  <xsl:template match="content-style">
    <xsl:choose>
      <xsl:when test="@format='smallcaps'">
        <xsl:value-of select="translate(normalize-space(.),'ABCDEFGHIJKLMNOPQRSTUVWXZ','abcdefghijklmnopqrstuvwxyz')"/>
      </xsl:when>
      <xsl:when test="@format='superscript'">
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- Namespace ntw-->
  <ntw:nums num="01" word="first"/>
  <ntw:nums num="02" word="second"/>
  <ntw:nums num="03" word="third"/>
  <ntw:nums num="04" word="forth"/>
  <ntw:nums num="05" word="fifth"/>
  <ntw:nums num="06" word="sixth"/>
  <ntw:nums num="07" word="seventh"/>
  <ntw:nums num="08" word="eighth"/>
  <ntw:nums num="09" word="nighth"/>
  <ntw:nums num="10" word="tenth"/>
  <!-- Namespace ntw ends -->
</xsl:stylesheet>

xml的HTML输出。

table style="frame-all width-100">
            <colgroup>
    <col class="colnum-1 colname-col1 colwidth-18"> //here / is missing in the end
    <col class="colnum-2 colname-col2 colwidth-82">//here / is missing in the end
            </colgroup>

感谢

欢迎使用堆栈溢出!

样式表没有指定输出方法,但是您的输出是可识别的HTML。所以样式表使用的是HTML输出方法,而不是XML输出方法。在HTML输出方法中,始终为空的元素(如col)使用SGML样式的结束标记,因此显示的输出是正确的。

如果您想要XML输出,请将xsl:output元素添加到样式表中(作为xsl:stylesheet的第一个子元素),并在其上指定method="xml",从而:

<xsl:output method="xml"/>

(请注意,如果您希望创建XHTML输出,则需要将输出元素放在XHTML命名空间中。)

当我向样式表中添加一个输出元素时,输出中的colgroup元素采用以下形式,这似乎就是您想要的:

  <colgroup>
    <col class="colnum-1 colname-col1 colwidth-18"/>
    <col class="colnum-2 colname-col2 colwidth-82"/>
  </colgroup>

相关内容

  • 没有找到相关文章

最新更新