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

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

 后台:

DataSet ds  =   new  DAL.JPDataAccess( " Select * from Article " ).IDs;

        XmlDataDocument xdd 
=   new  XmlDataDocument(ds);

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

 

TransformArticle.xsl:

 

<? xml version="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输出:

 

DataSet ds  =   new  DAL.JPDataAccess( " select * from Article " ).IDs;

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

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

你可能感兴趣的:(数据库和xml协同工作(2))