2012-08-13 56 views
1

我有一個XSLT 2.0,它將xhtml錶轉換爲InDesign XML表。此XSLT計算的最大數量<td>每行內的元素<tr>下面模板中的第7行(max(for $td in //tr return count($td/td)))。計數​​XHTML中的元素<table>與XSLT 1.0

<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處理器。

回答

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

應該做的。

+0

謝謝。 訣竅! – grefel 2012-08-14 09:37:22

+0

如果您在文檔中有多個表格,您需要修改第2行:' grefel 2012-08-14 16:53:43