grefel
grefel

Reputation: 95

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

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.

Upvotes: 1

Views: 1353

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167716

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

Upvotes: 2

Related Questions