rt
一个简单的例子就行
一个简单的例子就行
解决方案 »
- c# RichTextBox自动适应高度(在线等)分数不够,可以再加
- 图片切割算法求解
- XSL引用DLL里面的函数问题
- WebDateChooser 赋值问题
- 解铃还需系铃人,zswang请进!!!
- 哪位兄弟帮忙把这段vb代码翻译成c#,谢谢.
- 菜鸟:关于ascx文件
- 请问谁知道关于定义控件属性页的这个问题
- path=System.Configuration.ConfigurationSettings.AppSettings["PhotoPath"].ToString()+RelativeFile; 的具体解释。
- C# 怎么打印*.frf报表文件
- .net导出内容至word
- C# Panel分割
<!--模版 查询条件-->
<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">&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>
<?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>
我主要要的就是C#代码,让xlst生成xml的代码。
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();
}
也就是datatable中一行生成xml中一个大标签,这一行中的每一个数据生成一个小标签。本人第一次做这方面的程序,问的问题可能有些小白,希望大家见谅。
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);
}
[email protected]
可能我们的不一样吧,我这是把数据写到xml,再通过xslt把他显示出来,
我是把从数据库返回的ds直接转换
String xml = ds.GetXml();
发来吧,谢谢你了。