Count <td> Elements in xhtml <table> with XSLT 1.0

痞子三分冷 提交于 2019-12-02 14:04:52

问题


i've an XSLT 2.0 which transforms an xhtml Table into an InDesign XML Table. This XSLT counts the maximum number of <td> Elements within every row <tr> Line 7 in the template below (max(for $td in //tr return count($td/td))).

<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>

I've no idea how to realize this with XSLT 1.0 - any ideas would greatly appreciated! Sadly there is only a 1.0 Processor in the Workflow Pipeline.


回答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>

should do.



来源:https://stackoverflow.com/questions/11936094/count-td-elements-in-xhtml-table-with-xslt-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!