Showing:

Documentation
Used by
References
Overriding
Imported modules
Included from
Source
Stylesheet tables.xsl
Documentation

Description

TEI stylesheet for converting Word docx files to TEI

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Author: See AUTHORS

Id: $Id: from.xsl 6832 2009-10-12 22:42:59Z rahtz $

Copyright: 2008, TEI Consortium

Imported modules
Included from
Template w:tblparagraph
Namespace No namespace
Match w:tbl
Mode paragraph
References
Import precedence 16
Source
<xsl:template match="w:tbl" mode="paragraph">
  <xsl:choose>
    <xsl:when test="$tableMethod='word'">
      <xsl:copy>
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates/>
      </xsl:copy>
    </xsl:when>
    <xsl:when test="$tableMethod='cals'">
      <!-- preprocess the table to expand colspans, add row numbers, and
		   simplify vertical merge info -->
      <xsl:variable name="TABLE">
        <table xmlns="http://www.oasis-open.org/specs/tm9901">
          <xsl:attribute name="frame">
            <xsl:choose>
              <!-- lets face it, most tables do have
			   borders, especially in ISO; but not in footers! -->
              <xsl:when test="not(w:tblPr/w:tblBorders) and parent::w:ftr">
                <xsl:text>none</xsl:text>
              </xsl:when>
              <xsl:when test="not(w:tblPr/w:tblBorders)">
                <xsl:text>all</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:for-each select="w:tblPr/w:tblBorders">
                  <xsl:choose>
                    <xsl:when test="        w:top/@w:val='single' and        w:bottom/@w:val='single' and        w:right/@w:val='single' and        w:left/@w:val='single'">all</xsl:when>
                    <xsl:when test="          w:top/@w:val='single' and          w:bottom/@w:val='single' and          not(w:right/@w:val='single') and          not(w:left/@w:val='single')">topbot</xsl:when>
                    <xsl:when test="          w:top/@w:val='single' and          not(w:bottom/@w:val='single') and          not(w:right/@w:val='single') and          not(w:left/@w:val='single')">top</xsl:when>
                    <xsl:when test="          not(w:top/@w:val='single') and          w:bottom/@w:val='single' and          not(w:right/@w:val='single') and          not(w:left/@w:val='single')">bottom</xsl:when>
                    <xsl:when test="          not(w:top/@w:val='single') and          not(w:bottom/@w:val='single') and          w:right/@w:val='single' and          w:left/@w:val='single'">sides</xsl:when>
                    <xsl:when test="../../w:tr/w:tc/w:tcPr/w:tcBorders/w:top/@w:val='single'           and ../../w:tr/w:tc/w:tcPr/w:tcBorders/w:right/@w:val='single'">all</xsl:when>
                    <xsl:when test="../../w:tr/w:tc/w:tcPr/w:tcBorders/w:top/@w:val='single'">top</xsl:when>
                    <xsl:otherwise>
                      <xsl:text>none</xsl:text>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:for-each>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:attribute>
          <xsl:attribute name="colsep">
            <xsl:choose>
              <xsl:when test="w:tblPr/w:tblBorders/w:insideV/@w:val='single'">1</xsl:when>
              <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
          </xsl:attribute>
          <xsl:attribute name="rowsep">
            <xsl:choose>
              <xsl:when test="w:tblPr/w:tblBorders/w:insideH/@w:val='single'">1</xsl:when>
              <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
          </xsl:attribute>
          <xsl:call-template name="cals-table-header"/>
          <tgroup>
            <xsl:for-each select="w:tblGrid/w:gridCol">
              <colspec colnum="{position()}" colname="c{position()}">
                <xsl:attribute name="colwidth" select="concat(number(@w:w) div 20,'pt')"/>
              </colspec>
            </xsl:for-each>
            <tbody>
              <xsl:for-each select="w:tr">
                <xsl:copy>
                  <xsl:variable name="ROWPOS">
                    <xsl:number/>
                  </xsl:variable>
                  <xsl:for-each select="w:tc">
                    <xsl:variable name="VMERGE">
                      <xsl:choose>
                        <xsl:when test="w:tcPr/w:vMerge/@w:val='restart'">
                          <xsl:text>start</xsl:text>
                        </xsl:when>
                        <xsl:when test="w:tcPr[not(w:vMerge)]">
                          <xsl:text>start</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:text>continue</xsl:text>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:variable>
                    <xsl:variable name="innards">
                      <xsl:copy-of select="w:tcPr"/>
                    </xsl:variable>
                    <xsl:copy>
                      <xsl:variable name="N" select="position()"/>
                      <xsl:attribute name="rowsep">
                        <xsl:choose>
                          <xsl:when test="w:tcPr/w:tcBorders/w:bottom[@w:sz=0 or @w:val='nil']">
                            <xsl:text>0</xsl:text>
                          </xsl:when>
                          <xsl:when test="w:tcPr/w:tcBorders/w:bottom[@w:sz>0]">
                            <xsl:text>1</xsl:text>
                          </xsl:when>
                          <xsl:when test="parent::w:tr/following-sibling::w:tr[1]/w:tc[$N]/w:tcPr/w:tcBorders/w:top[@w:sz>0]">
                            <xsl:text>1</xsl:text>
                          </xsl:when>
                          <xsl:when test="ancestor::w:tbl/w:tblPr/w:tblBorders/w:insideH[@w:sz=0          or @w:val='nil']">
                            <xsl:text>0</xsl:text>
                          </xsl:when>
                          <xsl:when test="ancestor::w:tbl/w:tblPr/w:tblBorders/w:insideH">
                            <xsl:text>1</xsl:text>
                          </xsl:when>
                          <xsl:when test="not(parent::w:tr/following-sibling::w:tr)          and not(ancestor::w:ftr)">
                            <xsl:text>1</xsl:text>
                          </xsl:when>
                          <xsl:otherwise>
                            <xsl:text>0</xsl:text>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:attribute>
                      <xsl:attribute name="colsep">
                        <xsl:choose>
                          <xsl:when test="following-sibling::w:tc[1]/w:tcPr/w:tcBorders/w:left[@w:sz>0]">
                            <xsl:text>1</xsl:text>
                          </xsl:when>
                          <xsl:when test="w:tcPr/w:tcBorders/w:right[@w:sz=0 or @w:val='nil']">
                            <xsl:text>0</xsl:text>
                          </xsl:when>
                          <xsl:when test="w:tcPr/w:tcBorders/w:right[@w:sz>0]">
                            <xsl:text>1</xsl:text>
                          </xsl:when>
                          <xsl:when test="ancestor::w:tbl/w:tblPr/w:tblBorders/w:insideV[@w:sz=0          or @w:val='nil']">
                            <xsl:text>0</xsl:text>
                          </xsl:when>
                          <xsl:when test="not(ancestor::w:tbl/w:tblPr/w:tblBorders)          and ancestor::w:ftr">
                            <xsl:text>0</xsl:text>
                          </xsl:when>
                          <xsl:otherwise>
                            <xsl:text>1</xsl:text>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:attribute>
                      <xsl:attribute name="ROWPOS" select="$ROWPOS"/>
                      <xsl:attribute name="VMERGE" select="$VMERGE"/>
                      <xsl:copy-of select="@*"/>
                      <xsl:copy-of select="*"/>
                    </xsl:copy>
                    <xsl:if test="w:tcPr/w:gridSpan/@w:val">
                      <xsl:variable name="N" select="number(w:tcPr/w:gridSpan/@w:val)           cast as xs:integer"/>
                      <xsl:for-each select="2 to $N">
                        <w:tc DUMMY="yes">
                          <xsl:copy-of select="$innards"/>
                        </w:tc>
                      </xsl:for-each>
                    </xsl:if>
                  </xsl:for-each>
                </xsl:copy>
              </xsl:for-each>
            </tbody>
          </tgroup>
        </table>
        <!--
		    <xsl:comment>START</xsl:comment>
		    <TABLE>
		    <xsl:copy-of select="$TABLE"/>
		    </TABLE>
		    <xsl:comment>END</xsl:comment>
		-->
      </xsl:variable>
      <xsl:variable name="n">
        <xsl:number level="any"/>
      </xsl:variable>
      <xsl:for-each select="$TABLE">
        <xsl:apply-templates mode="innerTable">
          <xsl:with-param name="n" select="$n" tunnel="yes"/>
        </xsl:apply-templates>
      </xsl:for-each>
    </xsl:when>
    <xsl:otherwise>
      <table rend="rules">
        <xsl:call-template name="table-header"/>
        <xsl:for-each select="w:tr">
          <row>
            <xsl:for-each select="w:tc">
              <cell>
                <xsl:if test="w:p/w:pPr/w:jc">
                  <xsl:attribute name="teidocx:align">
                    <xsl:value-of select="w:p[1]/w:pPr/w:jc/@w:val"/>
                  </xsl:attribute>
                </xsl:if>
                <xsl:variable name="val" select="w:p[1]/w:pPr/w:pStyle/@w:val"/>
                <xsl:choose>
                  <xsl:when test="$val='[No Paragraph Style]'"/>
                  <xsl:when test="$val='Table text (9)'"/>
                  <xsl:otherwise>
                    <xsl:attribute name="rend">
                      <xsl:value-of select="$val"/>
                      <xsl:if test="w:tcPr/w:shd/@w:fill">
                        <xsl:text> background-color(</xsl:text>
                        <xsl:value-of select="w:tcPr/w:shd/@w:fill"/>
                        <xsl:text>)</xsl:text>
                      </xsl:if>
                    </xsl:attribute>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:if test="w:tcPr/w:gridSpan">
                  <xsl:attribute name="cols">
                    <xsl:value-of select="w:tcPr/w:gridSpan/@w:val"/>
                  </xsl:attribute>
                </xsl:if>
                <xsl:apply-templates/>
              </cell>
            </xsl:for-each>
          </row>
        </xsl:for-each>
      </table>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
Stylesheet location ../../../docx/from/tables/tables.xsl
Template *innerTable
Namespace No namespace
Match *
Mode innerTable
Import precedence 16
Source
<xsl:template match="*" mode="innerTable">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates mode="innerTable"/>
  </xsl:copy>
</xsl:template>
Stylesheet location ../../../docx/from/tables/tables.xsl
Template w:trinnerTable
Namespace No namespace
Match w:tr
Mode innerTable
References
Template cellContents
Import precedence 16
Source
<xsl:template match="w:tr" mode="innerTable">
  <row xmlns="http://www.oasis-open.org/specs/tm9901">
    <xsl:for-each select="w:tc[not(@DUMMY='yes')]">
      <xsl:choose>
        <xsl:when test="w:tcPr/w:vMerge[not(@w:val='restart')]"/>
        <xsl:otherwise>
          <entry>
            <xsl:variable name="ROWPOS" select="@ROWPOS"/>
            <xsl:variable name="COLPOS">
              <xsl:number/>
            </xsl:variable>
            <xsl:copy-of select="@rowsep"/>
            <xsl:copy-of select="@colsep"/>
            <xsl:attribute name="colname">
              <xsl:text>c</xsl:text>
              <xsl:value-of select="$COLPOS"/>
            </xsl:attribute>
            <xsl:if test="w:p/w:pPr/w:jc">
              <xsl:attribute name="align">
                <xsl:value-of select="w:p[w:pPr/w:jc/@w:val][1]/w:pPr/w:jc/@w:val"/>
              </xsl:attribute>
            </xsl:if>
            <xsl:if test="w:tcPr/w:gridSpan">
              <xsl:attribute name="namest">
                <xsl:text>c</xsl:text>
                <xsl:value-of select="$COLPOS"/>
              </xsl:attribute>
              <xsl:attribute name="nameend">
                <xsl:text>c</xsl:text>
                <xsl:value-of select="$COLPOS+number(w:tcPr/w:gridSpan/@w:val)-1"/>
              </xsl:attribute>
            </xsl:if>
            <xsl:if test="w:tcPr/w:vAlign">
              <xsl:attribute name="valign">
                <xsl:choose>
                  <xsl:when test="w:tcPr/w:vAlign/@w:val='center'">middle</xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="w:tcPr/w:vAlign/@w:val"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
            </xsl:if>
            <xsl:if test="w:tcPr/w:textDirection[@w:val='btLr']">
              <xsl:attribute name="rotate">
                <xsl:text>1</xsl:text>
              </xsl:attribute>
            </xsl:if>
            <xsl:if test="w:tcPr/w:vMerge/@w:val='restart'">
              <xsl:variable name="MOREROWS">
                <xsl:choose>
                  <xsl:when test="parent::w:tr/following-sibling::w:tr/w:tc[position()=$COLPOS][@VMERGE='start']">
                    <xsl:for-each select="(parent::w:tr/following-sibling::w:tr/w:tc[position()=$COLPOS][@VMERGE='start'])[1]">
                      <xsl:value-of select="@ROWPOS"/>
                    </xsl:for-each>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="parent::w:tr/following-sibling::w:tr[last()]/w:tc/@ROWPOS"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:variable>
              <!--
			  <xsl:message>start a merged cell at <xsl:value-of
			  select="$ROWPOS"/>/<xsl:value-of select="$COLPOS"/>
			  <xsl:text>: </xsl:text>
			  <xsl:value-of select="$MOREROWS"/>-<xsl:value-of
			  select="$ROWPOS"/> =<xsl:value-of select="."/>
			  </xsl:message>
		      -->
              <xsl:attribute name="morerows">
                <xsl:value-of select="number($MOREROWS) -            number($ROWPOS) -1"/>
              </xsl:attribute>
            </xsl:if>
            <xsl:choose>
              <xsl:when test="count(w:p)>1">
                <xsl:call-template name="cellContents"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:apply-templates/>
              </xsl:otherwise>
            </xsl:choose>
          </entry>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </row>
</xsl:template>
Stylesheet location ../../../docx/from/tables/tables.xsl
Template cellContents
Namespace No namespace
Overriding
Template cellContents
Import precedence 16
Source
<xsl:template name="cellContents">
  <xsl:apply-templates select="w:p" mode="inTable"/>
</xsl:template>
Stylesheet location ../../../docx/from/tables/tables.xsl
Template w:pinTable
Namespace No namespace
Match w:p
Mode inTable
Overriding
Template w:pinTable
Import precedence 16
Source
<xsl:template match="w:p" mode="inTable">
  <p rend="{w:pPr/w:pStyle/@w:val}">
    <xsl:apply-templates/>
  </p>
</xsl:template>
Stylesheet location ../../../docx/from/tables/tables.xsl
Template w:gridCol|w:tblBorders|w:tblCellMar|w:tblGrid|w:tblLayout|w:tblLook|w:tblPr|w:tblW|w:tc|w:tcBorders|w:tcPr|w:tcW|w:tr|w:trPr|w:vAlign|w:top|w:left|w:bottom|w:right|w:insideH|w:insideV
Documentation

Description

getting the basic table structure
Namespace No namespace
Match w:gridCol|w:tblBorders|w:tblCellMar|w:tblGrid|w:tblLayout|w:tblLook|w:tblPr|w:tblW|w:tc|w:tcBorders|w:tcPr|w:tcW|w:tr|w:trPr|w:vAlign|w:top|w:left|w:bottom|w:right|w:insideH|w:insideV
Mode #default
References
Parameter tableMethod
Import precedence 16
Source
<xsl:template match="w:gridCol|w:tblBorders|w:tblCellMar|w:tblGrid|w:tblLayout|w:tblLook|w:tblPr|w:tblW|w:tc|w:tcBorders|w:tcPr|w:tcW|w:tr|w:trPr|w:vAlign|w:top|w:left|w:bottom|w:right|w:insideH|w:insideV">
  <xsl:choose>
    <xsl:when test="$tableMethod='word'">
      <xsl:copy>
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates/>
      </xsl:copy>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
Stylesheet location ../../../docx/from/tables/tables.xsl
Template table-header
Namespace No namespace
Used by
Template w:tblparagraph
References
Variable Tabletitle
Import precedence 16
Source
<xsl:template name="table-header">
  <xsl:variable name="precedingTableTitle" select="preceding-sibling::w:p[w:pPr/w:pStyle/@w:val='TableTitle'             or w:pPr/w:pStyle/@w:val=$Tabletitle][1]"/>
  <xsl:if test="$precedingTableTitle and $precedingTableTitle/following-sibling::w:tbl[1] and generate-id()=generate-id($precedingTableTitle/following-sibling::w:tbl[1])">
    <head>
      <xsl:apply-templates select="$precedingTableTitle"/>
    </head>
  </xsl:if>
</xsl:template>
Stylesheet location ../../../docx/from/tables/tables.xsl
Template cals-table-header
Namespace No namespace
Used by
Template w:tblparagraph
References
Variable Tabletitle
Import precedence 16
Source
<xsl:template name="cals-table-header">
  <xsl:variable name="precedingTableTitle" select="preceding-sibling::w:p[w:pPr/w:pStyle/@w:val='TableTitle'             or w:pPr/w:pStyle/@w:val=$Tabletitle][1]"/>
  <xsl:if test="$precedingTableTitle and $precedingTableTitle/following-sibling::w:tbl[1] and generate-id()=generate-id($precedingTableTitle/following-sibling::w:tbl[1])">
    <title xmlns="http://www.oasis-open.org/specs/tm9901">
      <xsl:apply-templates select="$precedingTableTitle"/>
    </title>
  </xsl:if>
</xsl:template>
Stylesheet location ../../../docx/from/tables/tables.xsl