原格式如下:
<span row="1" col="1"/>
<span row="1" col="2"/> 
<span row="2" col="1"/>
.....................目标格式:
<row index="1">
  <col index="1"/>
</row>
.........应该如何处理?

解决方案 »

  1.   

    没看出什么对应关系。可以使用xslt将一个xml转换成另外一个xml的,
    类似
    http://blog.csdn.net/net_lover/archive/2002/05/16/6900.aspx
      

  2.   

    目标格式:
    <row index="1">
      <col index="1"/>
      <col index="2"/>
    </row>
    <row index="2">
      <col index="1">
      <col index="2">
    </row>
    ........
    这样没有对应吗?
      

  3.   

    cdcatalog.html<html>
    <body><script type="text/javascript">// Load XML 
    var xml = new ActiveXObject("Microsoft.XMLDOM")
    xml.async = false
    xml.load("cdcatalog.xml")// Load XSL
    var xsl = new ActiveXObject("Microsoft.XMLDOM")
    xsl.async = false
    xsl.load("cdcatalog.xsl")// Transform
    document.write(xml.transformNode(xsl))</script></body>
    </html>
    ------------------------
    cdcatalog.xml<?xml version="1.0" encoding="ISO-8859-1"?>
    <catalog>
      <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <year>1985</year>
      </cd>
    </catalog>------------------------
    cdcatalog.xsl
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">
      <html>
      <body>
        <h2>My CD Collection</h2> 
        <table border="1">
          <tr bgcolor="#9acd32">
            <th align="left">Title</th> 
            <th align="left">Artist</th> 
          </tr>
          <xsl:for-each select="catalog/cd">          ---- for-each读取xml节点
          <tr>
            <td><xsl:value-of select="title" /></td>
            <td><xsl:value-of select="artist" /></td>
          </tr>
          </xsl:for-each>
      </table>
      </body>
      </html>
    </xsl:template></xsl:stylesheet>
      

  4.   

    xsl:foreach----------循环SPAN
    xsl:if (@row)
    creamteelement(row)
    xsl:if (@col)
    createelement(col)
    .............
    伪代码,
    下面有结构转换的例子
    http://blog.csdn.net/honkerhero/archive/2007/03/14/1528837.aspx
      

  5.   

    解决了,用分组的方法实现
      <xsl:key name="row" match="@row" use="."/>
       <xsl:for-each select="span/@row[generate-id()=generate-id(key('row',.))]">
            <Row Index="{current()+1}">
                 <xsl:for-each select="../../span[@row = current()]">
                      <Cell Index="{@col}">
                           <xsl:value-of select="@text"/>
                       </Cell>
                    </xsl:for-each>
             </Row>
        </xsl:for-each>
      

  6.   

    http://blog.csdn.net/net_lover/archive/2002/05/16/6900.aspx
      

  7.   

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by opec (opec) -->
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:template match="/">
      <xsl:apply-templates/>
     </xsl:template>
     <xsl:template match="Table">
      <table>
       <xsl:if test="@ID!=''">
        <xsl:attribute name="ID"><xsl:value-of select="@ID"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@CssClass!=''">
        <xsl:attribute name="Class"><xsl:value-of select="@CssClass"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@Style!=''">
        <xsl:attribute name="Style"><xsl:value-of select="@Style"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@HAlign!=''">
        <xsl:attribute name="Align"><xsl:value-of select="@HAlign"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@VAlign!=''">
        <xsl:attribute name="VAlign"><xsl:value-of select="@VAlign"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@Width!=''">
        <xsl:attribute name="Width"><xsl:value-of select="@Width"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@Height!=''">
        <xsl:attribute name="Height"><xsl:value-of select="@Height"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@BgColor!=''">
        <xsl:attribute name="BgColor"><xsl:value-of select="@BgColor"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@Border!=''">
        <xsl:attribute name="Border"><xsl:value-of select="@Border"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@BorderColor!=''">
        <xsl:attribute name="BorderColor"><xsl:value-of select="@BorderColor"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@CellPadding!=''">
        <xsl:attribute name="CellPadding"><xsl:value-of select="@CellPadding"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@CellSpacing!=''">
        <xsl:attribute name="CellSpacing"><xsl:value-of select="@CellSpacing"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@OnClick!=''">
        <xsl:attribute name="OnClick"><xsl:value-of select="@OnClick"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@OnDbClick!=''">
        <xsl:attribute name="OnDbClick"><xsl:value-of select="@OnDbClick"/></xsl:attribute>
       </xsl:if>
       <xsl:apply-templates/>
      </table>
     </xsl:template>
     <xsl:template match="DataRow">
      <tr>
       <xsl:if test="@CssClass!=''">
        <xsl:attribute name="Class"><xsl:value-of select="@CssClass"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@Style!=''">
        <xsl:attribute name="Style"><xsl:value-of select="@Style"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@HAlign!=''">
        <xsl:attribute name="Align"><xsl:value-of select="@HAlign"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@VAlign!=''">
        <xsl:attribute name="VAlign"><xsl:value-of select="@VAlign"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@Width!=''">
        <xsl:attribute name="Width"><xsl:value-of select="@Width"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@Height!=''">
        <xsl:attribute name="Height"><xsl:value-of select="@Height"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@BgColor!=''">
        <xsl:attribute name="BgColor"><xsl:value-of select="@BgColor"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@BorderColor!=''">
        <xsl:attribute name="BorderColor"><xsl:value-of select="@BorderColor"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@OnClick!=''">
        <xsl:attribute name="OnClick"><xsl:value-of select="@OnClick"/></xsl:attribute>
       </xsl:if>
       <xsl:if test="@OnDbClick!=''">
        <xsl:attribute name="OnDbClick"><xsl:value-of select="@OnDbClick"/></xsl:attribute>
       </xsl:if>
       <xsl:for-each select="Column[@IsDisplay='True']">
        <td>
         <xsl:if test="@CssClass!=''">
          <xsl:attribute name="Class"><xsl:value-of select="@CssClass"/></xsl:attribute>
         </xsl:if>
         <xsl:if test="@Style!=''">
          <xsl:attribute name="Style"><xsl:value-of select="@Style"/></xsl:attribute>
         </xsl:if>
         <xsl:if test="@ColSpan!=''">
          <xsl:attribute name="ColSpan"><xsl:value-of select="@ColSpan"/></xsl:attribute>
         </xsl:if>
         <xsl:if test="@RowSpan!=''">
          <xsl:attribute name="RowSpan"><xsl:value-of select="@RowSpan"/></xsl:attribute>
         </xsl:if>
         <xsl:if test="@HAlign!=''">
          <xsl:attribute name="Align"><xsl:value-of select="@HAlign"/></xsl:attribute>
         </xsl:if>
         <xsl:if test="@VAlign!=''">
          <xsl:attribute name="VAlign"><xsl:value-of select="@VAlign"/></xsl:attribute>
         </xsl:if>
         <xsl:if test="@Width!=''">
          <xsl:attribute name="Width"><xsl:value-of select="@Width"/></xsl:attribute>
         </xsl:if>
         <xsl:if test="@Height!=''">
          <xsl:attribute name="Height"><xsl:value-of select="@Height"/></xsl:attribute>
         </xsl:if>
         <xsl:if test="@BgColor!=''">
          <xsl:attribute name="BgColor"><xsl:value-of select="@BgColor"/></xsl:attribute>
         </xsl:if>
         <xsl:if test="@BorderColor!=''">
          <xsl:attribute name="BorderColor"><xsl:value-of select="@BorderColor"/></xsl:attribute>
         </xsl:if>
         <xsl:if test="@OnClick!=''">
          <xsl:attribute name="OnClick"><xsl:value-of select="@OnClick"/></xsl:attribute>
         </xsl:if>
         <xsl:if test="@OnDbClick!=''">
          <xsl:attribute name="OnDbClick"><xsl:value-of select="@OnDbClick"/></xsl:attribute>
         </xsl:if>
         <xsl:apply-templates/>
        </td>
       </xsl:for-each>
      </tr>
     </xsl:template>
     <xsl:template match="Value">
      <xsl:apply-templates/>
     </xsl:template>
     <xsl:template match="BR">
      <br/>
      <xsl:value-of select="."/>
     </xsl:template>
      <xsl:template match="Page">
      <p style="page-break-after:always"></p>
     </xsl:template>
    </xsl:stylesheet>
      

  8.   

    楼上照办我BLOG上的东西,不厚道啊