如何添加节点而不是错过的rowspan单元格

时间:2015-04-14 05:19:38

标签: xml xslt-1.0

请提供建议。

我已经改变了表格:

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

我转换表:

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

我有:

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

但我需要得到:

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

这意味着我需要设置&#34; cell&#34;,这些都受到&#34; action&#34; rowspan,具有属性&#34; nottransform&#34;的空白节点。 我怎样才能做到这一点?是否有可能喜欢?

感谢您的帮助。

0 个答案:

没有答案