xsl cals 表:跨单元格,使用 colspec、namest 和 nameend [英] xsl cals tables: span cells, using colspec, namest and nameend

查看:41
本文介绍了xsl cals 表:跨单元格,使用 colspec、namest 和 nameend的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对跨越表格的单元格很着迷.我的表有 3 列.下面你看到一行(只有片段):

I'm getting crazy with spanning cells of a table. My table is of 3 columns. Below you see one row (only fragment):

<tgroup>
    <colspec name="x">
    <colspec name="y">
    <colspec name="z">
    <tbody>
        <row>
        <entry>abc
        <entry namest="y" nameend="z">blabla

第二个条目 (blabla) 应跨越两个条目(=表格单元格).信息在属性nameend"和namest"中.

The second entry (blabla) should span two entry (=table cells). The information is in the attributes "nameend" and "namest".

我的方法是:

  1. xsl:template match="entry" ...

获取(此处为3)和(此处为2)

get the position number of <colspec name=z> (here 3) and of <colspec name="y"> (here 2) <??????>

减去 z 和 y (=1) 加 1:result=3

substract z and y (=1) add 1: result=3

  <xsl:param name="colspan">
      <xsl:value-of select="($nameend)-($namest)+(1)"/>
  </xsl:param>

  • 在条目模板中使用 result=3 作为属性colspan"

  • use the result=3 as attribute "colspan" in the entry template

    <fo:table-cell number-columns-spanned="{$colspan}" 
    

  • 但是我看不到解决我的第二步的方法(????)

    But I see no way to solve my second step (????)

    有什么想法吗??谢谢皮亚

    Any ideas?? Thanks Pia

    附言不,我不能更改源文件

    P.S. No, I can not change the source file

    推荐答案

    鉴于此输入 XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <tgroup>
      <colspec name="x"/>
      <colspec name="y"/>
      <colspec name="z"/>
      <tbody>
        <row>
          <entry>abc</entry>
          <entry namest="y" nameend="z">blabla 1</entry>
        </row>
        <row>
          <entry namest="x" nameend="z">blabla 2</entry>
        </row>
        <row>
          <entry namest="x" nameend="y">blabla 3</entry>
          <entry>cde</entry>
        </row>
      </tbody>
    </tgroup>
    

    这个 XSLT:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" indent="yes"/>
    
      <xsl:template match="@* | node()">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="entry[@namest and @nameend]">
        <xsl:variable name="namest" select="@namest"/>
        <xsl:variable name="nameend" select="@nameend"/>
        <xsl:variable name="namestPos" select="count(ancestor::tgroup/colspec[@name=$namest]/preceding-sibling::colspec)"/>
        <xsl:variable name="nameendPos" select="count(ancestor::tgroup/colspec[@name=$nameend]/preceding-sibling::colspec)"/>
    
        <table-cell number-columns-spanned="{$nameendPos - $namestPos + 1}">
          <xsl:apply-templates/>
        </table-cell>
      </xsl:template>
    </xsl:stylesheet>
    

    将产生此输出:

    <?xml version="1.0" encoding="UTF-8"?>
    <tgroup>
      <colspec name="x"/>
      <colspec name="y"/>
      <colspec name="z"/>
      <tbody>
          <row>
             <entry>abc</entry>
             <table-cell number-columns-spanned="2">blabla 1</table-cell>
          </row>
          <row>
             <table-cell number-columns-spanned="3">blabla 2</table-cell>
          </row>
          <row>
             <table-cell number-columns-spanned="2">blabla 3</table-cell>
             <entry>cde</entry>
          </row>
      </tbody>
    </tgroup>
    

    注意事项:

    • 尽管您写道,减去 z 和 y (=1) 加 1:结果=3",但我认为你的意思是result=2".
    • entry 被映射到 table-cell@number-columns-spanned 属性值,这是问题的关键方面.重新映射周围的元素和到 fo 命名空间的映射还有待完成.
    • Although you wrote, "subtract z and y (=1) add 1: result=3", I assume that you meant "result=2".
    • entry is mapped to table-cell with the desired @number-columns-spanned attribute value, which is the key aspect of the question. Remapping of the surrounding elements and mapping to the fo namespace too remain to do.

    这篇关于xsl cals 表:跨单元格,使用 colspec、namest 和 nameend的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆