请给出一段xslt代码,使用xml数据输出如下HTML数据:xml:
<cellphones>
  <brand name="Moto">
    <product name="A3000" publish_year = "2008" platform = "windows"/>
    <product name="A3100" publish_year = "2009" platform= "windows"/>
    <product name="Droid" publish_year = "2009" platform= "android"/>
  </brand>
  <brand name="HTC">
    <product name="Tatoo" publish_year = "2009" platform= "android"/>
    <product name="Hero" publish_year = "2009" platform= "android"/>
    <product name="Touch Pro II" publish_year = "2009" platform= "windows"/>
    <product name="Dream" publish_year = "2008" platform= "android"/>
  </brand>
  <brand name="Nokia">
    <product name="N97" publish_year = "2009" platform= "symbian"/>
    <product name="E71" publish_year = "2008" platform= "symbian"/>
    <product name="N73" publish_year = "2007" platform= "symbian"/>
  </brand>
</cellphones> html:<table>
    <tr>
        <td rowspan="3">
            Moto
        </td>
        <td>A3000</td>
        <td>2008</td>
        <td>windows</td>
    </tr>
    <tr> 
        <td>A3100</td>
        <td>2009</td>
        <td>windows</td>
    </tr>
    <tr> 
        <td>Droid</td>
        <td>2009</td>
        <td>android</td>
    </tr>
    <tr>
        <td rowspan="4">
            HTC
        </td>
        <td>Tatoo</td>
        <td>2009</td>
        <td>android</td>
    </tr>
    <tr> 
        <td>Hero</td>
        <td>2009</td>
        <td>android</td>
    </tr>
    <tr> 
        <td>Touch Pro II</td>
        <td>2009</td>
        <td>windows</td>
    </tr>
    <tr> 
        <td>Dream</td>
        <td>2008</td>
        <td>android</td>
    </tr>
    <tr>
        <td rowspan="3">
            Nokia
        </td>
        <td>N97</td>
        <td>2009</td>
        <td>symbian</td>
    </tr>
    <tr> 
        <td>E71</td>
        <td>2009</td>
        <td>symbian</td>
    </tr>
    <tr> 
        <td>N73</td>
        <td>2007</td>
        <td>symbian</td>
    </tr> 
</table>

解决方案 »

  1.   

    System.Xml.XmlDocument dom = new System.Xml.XmlDocument();
    dom.LoadXml(xml);
    foreach (System.Xml.XmlNode node in dom.ChildNodes)
     {   
        if(node.Name !="xml")
         Response.Write(GetNode(node));               
    }
     string GetNode(System.Xml.XmlNode node)
       {
              string str = node.InnerText;
              str+=node.Attributes["name"].InnerText.Trim()
              if (node.HasChildNodes)
              {
                    str = "";
                    foreach (System.Xml.XmlNode n in node.ChildNodes)
                    {
                        str += GetNode(n);
                    }
             }
             return str;
         }
      

  2.   

    phone.xml
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet type="text/xsl" href="phone.xsl"?>
    <cellphones> 
      <brand name="Moto"> 
        <product name="A3000" publish_year = "2008" platform = "windows"/>
        <product name="A3100" publish_year = "2009" platform= "windows"/>
        <product name="Droid" publish_year = "2009" platform= "android"/>
      </brand> 
      <brand name="HTC"> 
        <product name="Tatoo" publish_year = "2009" platform= "android"/>
        <product name="Hero" publish_year = "2009" platform= "android"/> 
        <product name="Touch Pro II" publish_year = "2009" platform= "windows"/> 
        <product name="Dream" publish_year = "2008" platform= "android"/> 
      </brand> 
      <brand name="Nokia"> 
        <product name="N97" publish_year = "2009" platform= "symbian"/>
        <product name="E71" publish_year = "2008" platform= "symbian"/> 
        <product name="N73" publish_year = "2007" platform= "symbian"/> 
      </brand> 
    </cellphones>phone.xsl
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method='html' version='1.0' encoding='ISO-8859-1' indent='yes'/>
    <xsl:template match="/">
      <html>
      <body> 
        <table border="1">
    <xsl:for-each select="cellphones/brand">     
    <xsl:for-each select="product">
    <tr>
           <xsl:if test="position()=1">   
    <td> 
    <xsl:attribute name="rowspan">
    <xsl:value-of select="count(../product)"/>
    </xsl:attribute>    
    <xsl:value-of select="../@name"/>
    </td>
     </xsl:if>   
    <td>
    <xsl:value-of select="@name"/>
    </td>
    <td>
    <xsl:value-of select="@publish_year"/>
    </td>
    <td>
    <xsl:value-of select="@platform"/>
    </td>
    </tr>   
    </xsl:for-each>
            </xsl:for-each>
        </table>
      </body>
      </html>
    </xsl:template>
    </xsl:stylesheet>
      

  3.   

    共同学习了一下,参考
    http://www.cnblogs.com/yeti/articles/667117.html另,结贴率太低!