N Ganesh Babu
N Ganesh Babu

Reputation: 1

w:vMerge from Word ML to rowspan in HTML

we are converting Word File into XML using XSLT. How we can get the rowspan attribute in tables.

This is XSLT code to achieve this.

<xsl:template match="w:tc">
    <xsl:choose>
        <xsl:when test="w:tcPr/w:vMerge[@w:val='restart'] or w:tcPr[not(w:vMerge)]">
            <td>
                <xsl:if test="w:tcPr/w:gridSpan">
                    <xsl:attribute name="colspan" select="w:tcPr/w:gridSpan/@w:val"/>
                </xsl:if>
                <xsl:if test="w:tcPr/w:vMerge[@w:val='restart']">
                <xsl:value-of select="count(parent::w:tr/following-sibling::w:tr[w:tc/w:tcPr/w:vMerge[not(@w:val)]])"/>
                </xsl:if>
                <xsl:apply-templates/>
            </td>
        </xsl:when>
    </xsl:choose>
</xsl:template>

However this code is counting all the rows. I need to limit the count to the next @w:val='restart'. Is this possible in XSLT?

Upvotes: 0

Views: 517

Answers (1)

Ghislain Fourny
Ghislain Fourny

Reputation: 7279

If you are using XSLT 3.0, there is the << comparison operator that tests whether a node is before another node (from 2.0), and you can bind the next @w:val='restart' with a let. I could imagine something along the lines of:

let $guard := parent::w:tr/following-sibling::w:tr[@w:val='restart'][1]
  (: Note: I probably got the above XPath wrong so it needs fine-tuning :)
return count(
  parent::w:tr/following-sibling::w:tr
    [. << $guard]
    [w:tc/w:tcPr/w:vMerge[not(@w:val)]]
)

Upvotes: 0

Related Questions