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