【问题标题】:Count <td> Elements in xhtml <table> with XSLT 1.0使用 XSLT 1.0 计算 xhtml <table> 中的 <td> 元素
【发布时间】:2012-08-13 14:12:43
【问题描述】:

我有一个 XSLT 2.0,它将 xhtml 表转换为 InDesign XML 表。此 XSLT 计算下面模板 (max(for $td in //tr return count($td/td))) 中每行 &lt;tr&gt; 第 7 行中 &lt;td&gt; 元素的最大数量

<xsl:template match="table">
    <xsl:element name="id_table">
        <xsl:attribute name="aid:trows">
            <xsl:value-of select="count(child::*/tr)"/>
        </xsl:attribute>
        <xsl:attribute name="aid:tcols">
            <xsl:value-of select="max(for $td in //tr return count($td/td))"/>
        </xsl:attribute>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>

我不知道如何使用 XSLT 1.0 实现这一点 - 任何想法都将不胜感激!遗憾的是,工作流管道中只有一个 1.0 处理器。

【问题讨论】:

    标签: xml xslt xhtml adobe-indesign


    【解决方案1】:
    <xsl:attribute name="aid:tcols">
      <xsl:for-each select="//tr">
        <xsl:sort select="count(td)" order="descending"/>
        <xsl:if test="position() = 1">
          <xsl:value-of select="count(td)"/>
        </xsl:if>
      </xsl:for-each>
    </xsl:attribute>
    

    应该这样做。

    【讨论】:

    • 如果文档中有多个表格,则需要修改第 2 行:&lt;xsl:for-each select=".//tr"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多