rt
一个简单的例子就行

解决方案 »

  1.   


      <!--模版 查询条件-->
      <xsl:template match="/DataSet/Condition" name="ReportCondition">    <table style="width: 730px; height: 21px; border:solid 1px black; border-bottom:none;" cellpadding="0"
            cellspacing="0">
          <tr>
            <td colspan="4" style="background: silver; width: 50%; font-size: 9pt;font-weight: bold;border-right:solid 1px black;">
              报表生成设置
            </td>
            <td colspan="5">
              <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
            </td>
          </tr>
        </table>
        <table style="width: 730px; height: 42px; border-left: solid 1px black; border-right: solid 1px black;
                                    font-size: 9pt;border:solid 1px black;" cellpadding="0" cellspacing="0">
          <tr style="height: 21px;">
            <td style="width: 65px; height: 20px;">
              客户名称:
            </td>
            <td style="width:310px; height:20px;text-align:left;margin-right:10px;" colspan="3">
              <xsl:value-of select="//Item[@Type='CusNames']/@Value" />
            </td>
            <td style="width: 350px; height: 20px;" colspan="5">
              收发片区: <xsl:value-of select="//Item[@Type='ColNames']/@Value" />
            </td>      </tr>
          <tr style="height: 21px;">
            <td style="width: 370px; height: 20px;" colspan="4">
              衣物类型: <xsl:value-of select="//Item[@Type='CloNames']/@Value" />
            </td>
            <td style="width: 350px; height: 20px;" colspan="5">
              统计时段: <xsl:value-of select="//Item[@Type='TimeSpan']/@Value" />
            </td>      </tr>
        </table>
      </xsl:template>
      

  2.   


    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <?xml-stylesheet type='text/xsl' href='ClothLives.xslt'?>
    <DataSet>
      <Condition>
        <Item Type="CompanyName" Value="上海市第一人民医院"></Item>
        <Item Type="MakeDate" Value="2010/12/09"></Item>
        <Item Type="CustomerName" Value="上海第一人民医院,上海宝山医院"></Item>
        <Item Type="CustomerID" Value="158,159"></Item>
        <Item Type="ClothType" Value="所有类型"></Item>
        <Item Type="CollectionRegion" Value="所有片区"></Item>
        <Item Type="CollectionRegions" Value="NULL"></Item>
        <Item Type="ClothTypeIDS" Value="213,214,215,220,221,222,223,224"></Item>
        <Item Type="StartTime" Value="2010-12-01 00:00:00"></Item>
        <Item Type="EndTime" Value="2010-12-07 00:00:00"></Item>
        <Item Type="TimeSpan" Value="2010/12/01-2010/12/07"></Item>
        <Item Type="Unit" Value="件"></Item>
        <Item Type="Logo" Value="images/image002.gif"></Item>
        <Item Type="timeType" Value="日"></Item>
        <Item Type="type" Value="合计"></Item>
        <Item Type="isMultCustomer" Value="1"></Item>
        <Item Type="ColumnCount" Value="6"></Item>
      </Condition>
      

  3.   

    C#程序里怎么写?
    我主要要的就是C#代码,让xlst生成xml的代码。
      

  4.   


     protected void TransformXml(XmlDocument doc)
            {
                string xslPath = Server.MapPath("xslt/ClothRental.xslt");
                XsltSettings settings = new XsltSettings(true, true);
                XslCompiledTransform xsl = new XslCompiledTransform();
                xsl.Load(xslPath, settings, null);            StringWriter writer = new StringWriter();
                XPathNavigator na = doc.CreateNavigator();
                xsl.Transform(na, null, writer);            string code = writer.ToString();
            }
      

  5.   

    XSLT转换XML
      

  6.   

    最后一个问题:我要把datatable中的数据按照xlst的格式生成xml,
    也就是datatable中一行生成xml中一个大标签,这一行中的每一个数据生成一个小标签。本人第一次做这方面的程序,问的问题可能有些小白,希望大家见谅。
      

  7.   

     StringBuilder sb = new StringBuilder();
                sb.Append("<?xml version='1.0' encoding='utf-8' standalone='yes'?> <?xml-stylesheet type='text/xsl' href='ClothLives.xslt'?>");            sb.Append("<DataSet>");
                //Condition节点
                sb.Append("<Condition>");            sb.Append(CreateCondition("CompanyName", companyName));
                sb.Append(CreateCondition("MakeDate", ConvertTime(DateTime.Now)));
                sb.Append(CreateCondition("CusNames", customerName));
                sb.Append(CreateCondition("CusIDs", cusIDs));
                sb.Append(CreateCondition("CloNames", clothType));
                sb.Append(CreateCondition("ColNames", collectionRegion));
                sb.Append(CreateCondition("CloIDs", cloIDs));
                sb.Append(CreateCondition("ColIDs", colIDs));
                sb.Append(CreateCondition("StartTime", start.ToString("yyyy-MM-dd HH:mm:ss")));
                sb.Append(CreateCondition("EndTime", end.ToString("yyyy-MM-dd HH:mm:ss")));
                sb.Append(CreateCondition("TimeSpan", string.Format("{0}~{1}", start.ToString("yyyy/MM/dd"), end.ToString("yyyy/MM/dd"))));
                sb.Append(CreateCondition("Unit", unit));
                sb.Append(CreateCondition("Logo", logo));
                sb.Append(CreateCondition("ColumnCount", columnsCount.ToString()));
                sb.Append("</Condition>");            //Columns节点
                sb.Append("<Columns>");            //添加类别和尺寸的列
                for (int i = 0; i < 4; i++)
                {
                    sb.Append(CreateColumns("Col", "Type", "Categroy", "Name", dt.Columns[i].ColumnName));
                }
     /// <summary>
            /// 为Xml添加节点和属性值(两个属性)
            /// </summary>
            /// <param name="nodeName">节点名称</param>
            /// <param name="attr1">属性名称1</param>
            /// <param name="attrValue1">属性值1</param>
            /// <param name="attr2">属性名称2</param>
            /// <param name="attrValue2">属性值2</param>
            /// <returns>xml文本</returns>
            private static string CreateColumns(string nodeName, string attr1, string attrValue1, string attr2, string attrValue2)
            {
                return string.Format("<{0} {1}=\"{2}\" {3}=\"{4}\" />", nodeName, attr1, attrValue1, attr2, attrValue2);
            }
      

  8.   

    老兄,你这些个代码又和XSLT转换XML脱节了吧,你这是C#直接生成一个XML了。要不你有关于XSLT转换XML的的代码发我邮箱里吧。
    [email protected]
      

  9.   


    可能我们的不一样吧,我这是把数据写到xml,再通过xslt把他显示出来,
      

  10.   

    好的,就这个就行,
    我是把从数据库返回的ds直接转换
    String xml = ds.GetXml();
    发来吧,谢谢你了。