0

Please help with advice.

I have transformed table:

<?xml version="1.0"?>
<html>
  <block><string sharedString="0">first 1</string>
      <string sharedString="0">first 2</string>     
      <string sharedString="0">first 3</string>     
    </block>
  <block><string sharedString="0" rowspan="3">s11</string>
     <string sharedString="0">s22</string>
     <string sharedString="0" rowspan="3">s55</string> 
    </block>
  <block><string sharedString="0">s33</string>
    </block>
  <block><string sharedString="0">s44</string>
    </block>
</html>

I transform table:

<?xml version="1.0" encoding="utf-8"?>  
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <sheet>        
      <xsl:apply-templates select="//block" />
    </sheet> 
  </xsl:template>


  <xsl:template match="block">   
    <row>
      <xsl:attribute name="r">
        <xsl:value-of select="position()" />
      </xsl:attribute>
      <xsl:if test="@src">
        <xsl:attribute name="src">
          <xsl:value-of select="@src" />
        </xsl:attribute>
      </xsl:if>
      <xsl:apply-templates select="string" />
    </row>
  </xsl:template>

  <xsl:template match="string"> 
    <c>
      <xsl:attribute name="col_position">
        <xsl:value-of select="position()" />
      </xsl:attribute>            

      <xsl:if test="count(./sharedString) > 1">

      </xsl:if>            

      <xsl:for-each select="@*">
        <xsl:copy-of select="." />
      </xsl:for-each>                                                                       

      <xsl:value-of select="normalize-space(text())"/>
    </c>
    <xsl:if test="@colspan">
      <xsl:call-template name="for">
        <xsl:with-param name="n" select="./@colspan"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template name="for">
    <xsl:param name="i" select="0"/>
    <xsl:param name="n"/>

    <xsl:if test="$i &lt; $n - 1">
        <c nottransform="1" />

        <xsl:call-template name="for">
            <xsl:with-param name="i" select="$i + 1"/>
            <xsl:with-param name="n" select="$n"/>
        </xsl:call-template>

    </xsl:if>
  </xsl:template>    
</xsl:stylesheet>

And I have:

<?xml version="1.0"?>
<sheet>
  <row r="1">
    <c col_position="1" sharedString="0">first 1</c>
    <c col_position="2" sharedString="0">first 2</c>
    <c col_position="3" sharedString="0">first 3</c>
  </row>
  <row r="2">
    <c col_position="1" sharedString="0" rowspan="3">s11</c>
    <c col_position="2" sharedString="0">s22</c>
    <c col_position="3" sharedString="0" rowspan="3">s55</c>
  </row>
  <row r="3">
    <c col_position="1" sharedString="0">s33</c>
  </row>
  <row r="4">
    <c col_position="1" sharedString="0">s44</c>
  </row>
</sheet>

But I need to get:

<?xml version="1.0"?>
<sheet>
  <row r="1">
    <c col_position="1" sharedString="0">first 1</c>
    <c col_position="2" sharedString="0">first 2</c>
    <c col_position="3" sharedString="0">first 3</c>
  </row>
  <row r="2">
    <c col_position="1" sharedString="0" rowspan="3">s11</c>
    <c col_position="2" sharedString="0">s22</c>
    <c col_position="3" sharedString="0" rowspan="3">s55</c>
  </row>
  <row r="3">
    <c col_position="1" sharedString="0" nottransform="1" />
    <c col_position="2" sharedString="0">s33</c>
    <c col_position="3" sharedString="0" nottransform="1" />
  </row>
  <row r="4">
    <c col_position="1" sharedString="0" nottransform="1" />
    <c col_position="2" sharedString="0">s44</c>
    <c col_position="3" sharedString="0" nottransform="1" />
  </row>
</sheet>

This means that I need to put in place "cells", which are subject to the "action" rowspan, blank nodes with attribute "nottransform". How can I do that? Is it possible to like?

Thanks for the help.

potame
  • 7,597
  • 4
  • 26
  • 33
  • I don't see any `@colspan` attribute on the `` element - your condition (``) will never be fulfilled.... – potame Apr 14 '15 at 07:22
  • This is possible, but quite complex. See a somewhat similar problem here; http://stackoverflow.com/questions/21608877/please-suggest-for-xslt-code-for-table-rowspan-and-colspan-issues/27217608#27217608 – michael.hor257k Apr 14 '15 at 11:54

0 Answers0