2016-08-16 8 views
0

Nous convertissons le fichier Word en XML en utilisant XSLT. Comment nous pouvons obtenir l'attribut rowspan dans les tables.w: vMerge de Word ML vers rowspan en HTML

Il s'agit d'un code XSLT pour cela.

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

Toutefois, ce code compte toutes les lignes. Je dois limiter le compte à la prochaine @w: val = 'restart'. Est-ce possible dans XSLT?

Répondre

0

Si vous utilisez XSLT 3.0, il est l'opérateur de comparaison << qui teste si un nœud est avant un autre nœud (de 2,0), et vous pouvez lier la prochaine @w:val='restart' avec un nous. Je pourrais imaginer quelque chose du genre:

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)]] 
) 
+0

Nous n'utilisons que la version opensource Saxon, c'est-à-dire HE. XSLT 3.0 ne fait pas partie de HE –