Count Elements in xhtml with XSLT 1.0

2019-03-02 06:25发布

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条回答
2楼-- · 2019-03-02 06:44
<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.

查看更多
登录 后发表回答
向帮助了您的知道网友说句感谢的话吧!