0

I need to create two separate templates that fill space. One that occupies 49 spaces and the other fills 549 spaces. I found on template that I thinks may work but I can't really tell what its doing, I'm new to xml.

<!-- Template Filler-->
  <xsl:template name="Filler">
    <xsl:param name="fillercount" select="1"/>
    <xsl:if test="$fillercount > 0">
      <table class="tabledetails">
        <tr>
          <td>
            <xsl:value-of select="translate(' ', ' ', '&#160;')"/>
          </td>
        </tr>
      </table>
      <xsl:call-template name="Filler">
        <xsl:with-param name="fillercount" select="$fillercount - 1"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

Is this what I need , and call it with select="49" or am I reading it wrong. If this is now what I need how can I achieve this?

4

1 回答 1

0

你还没有说你想要什么输出。如果您使用参数 49 调用此模板,则输出将包含 49 个表,每个表包含一行和一列,单元格的内容是不间断的空格字符。生成不间断空格字符的方式非常奇怪: translate() 调用将空格字符作为输入,然后通过用不间断空格替换所有空格来处理它。大概它是代码的缩减版本,在某个阶段做了一些更明智的事情。

代码的基本结构是一个递归模板,它接受一个参数,比如 49,输出一个“事物”(在本例中为单例表),然后调用自身再次执行 N-1 次。这是在 XSLT 1.0 中做某事 N 次的合适方法。(在 2.0 中,您可以使用<xsl:for-each select="1 to $N">,这对于使用命令式语言的程序员来说更加直观。)

于 2012-09-28T21:45:36.817 回答