数据库和xml协同工作(2)

1。用xml控件来显示数据库信息:

后台:

DataSetds = new DAL.JPDataAccess( " Select*fromArticle " ).IDs;

XmlDataDocumentxdd
= new XmlDataDocument(ds);

Xml1.Document
= xdd;
Xml1.TransformSource
= (MapPath( " TransformArticle.xsl " ));

TransformArticle.xsl:

<? xmlversion="1.0"encoding="utf-8" ?>

< xsl:stylesheet version ="1.0"
xmlns:xsl
="http://www.w3.org/1999/XSL/Transform" >

< xsl:template match ="Table" >
< p >
< table width ="100%" border ="1" cellpadding ="10" >
< tr >
< td bgColor ="yellow" >
< strong >
< xsl:value-of select ="articleTitle" />
</ strong >
</ td >
</ tr >
< tr >
< td bgColor ="#eeeeee" >
< xsl:value-of select ="content" />
</ td >
</ tr >
</ table >
</ p >
</ xsl:template >

</ xsl:stylesheet >

2。不用xml控件,同时把数据库转换来的表以xml+xsl输出:

DataSetds = new DAL.JPDataAccess( " select*fromArticle " ).IDs;

// 写入输出流
XmlDataDocumentxdd = new XmlDataDocument(ds);
// XslTransformxtf=newXslTransform();
XslCompiledTransformxtf = new XslCompiledTransform();
xtf.Load(MapPath(
" TransformArticle.xsl " ));
xtf.Transform(xdd,
new XsltArgumentList(),Response.OutputStream);

// 写入文件
StreamWritersw = new StreamWriter(MapPath( " transformed.txt " ));
xtf.Transform(xdd,
new XsltArgumentList(),sw);
sw.Close();

你可能感兴趣的:(xml,工作,XSL)