XSLT命令[XML格式轉換]
1.循環 <xsl:for-each...>
<xsl:for-each select="BookList/Item">
<tr>
<th align="left"> <xsl:value-of select=".//title" /></th>
<td><xsl:value-of select=".//categroy" /></td>
<td><xsl:value-of select=".//release-date" /></td>
<td><xsl:value-of select=".//author" /></td>
<td><xsl:value-of select="@price" /></td>
</tr>
</xsl:for-each>
2.排序 <xsl:sort...>
3.條件處理 <xsl:if...>或<xsl:choose...>或<xsl:when...>
4.名稱模板
<xsl:template name...<xsl:template name...>,<xsl:param...>
<xsl:with-param...>,<xsl:call-template...>
5.編號方式 <xsl:number value format...>
xml文檔[Article.xml] <?XML version="1.0" encoding="gb2312" ?>
<?XML-stylesheet type='text/xsl' href='Article.xsl'?>
<Articles>
<Article>
<ArticleID>2897</ArticleID>
<Title>[分享]千萬數量級分頁存儲過程(帶效果演示)</Title>
<Author>網絡</Author>
<Abstract>[分享]千萬數量級分頁存儲過程(帶效果演示)</Abstract>
<PostDateTime>2006-02-27 18:29:53</PostDateTime>
<Dots>7</Dots>
<ColumnURL>/web/Article/vIEwColumn.ASPx?ColID=19</ColumnURL>
<ColumnID>19</ColumnID>
<ColumnName>SQL Server</ColumnName>
<FileType>1</FileType>
<FilePath>resource/SQL Server/2006-02-27/20060227182953.htm</FilePath>
<Editor>網絡</Editor>
<EditDateTime>2006-02-27 18:29:53</EditDateTime>
<Content>
[分享]千萬數量級分頁存儲過程(帶效果演示)效果演示:
http://www.cn5135.com/_App/OpportunitIEs/QueryResult.ASPx
CREATE PROCEDURE CN5135_SP_Pagination
/******************************************************************
千萬數量級分頁存儲過程
*******************************************************************
參數說明:
1.Tables :表名稱,視圖
2.PrimaryKey :主關鍵字
3.Sort :排序語句,不帶Order By 比如:NewsID Desc,OrderRows Asc
4.CurrentPage :當前頁碼
5.PageSize :分頁尺寸
6.Filter :過濾語句,不帶Where
7.Group :Group語句,不帶Group By
效果演示:http://www.cn5135.com/_App/OpportunitIEs/QueryResult.ASPx
***************************************************************/
(
@Tables varchar(1000),
@PrimaryKey varchar(100),
@Sort varchar(200) = NULL,
@CurrentPage int = 1,
@PageSize int = 10,
@FIElds varchar(1000) = '*',
@Filter varchar(1000) = NULL,
@Group varchar(1000) = NULL
)
AS
/*默認排序*/
IF @Sort IS NULL OR @Sort = ''
SET @Sort = @PrimaryKey
DECLARE @SortTable varchar(100)
DECLARE @SortName varchar(100)
DECLARE @strSortColumn varchar(200)
>DECLARE @Operator char(2)
DECLARE @type varchar(100)
DECLARE @prec int
/*設定排序語句.*/
IF CHARINDEX('DESC',@Sort)>0
BEGIN
SET @strSortColumn = REPLACE(@Sort, 'DESC', '')
SET @Operator = '<='
END
ELSE
BEGIN
IF CHARINDEX('ASC', @Sort) = 0
SET @strSortColumn = REPLACE(@Sort, 'ASC', '')
SET @Operator = '>='
END
IF CHARINDEX('.', @strSortColumn) > 0
BEGIN
SET @SortTable = SUBSTRING(@strSortColumn, 0, CHARINDEX('.',@strSortColumn))
SET @SortName = SUBSTRING(@strSortColumn, CHARINDEX('.',@strSortColumn) + 1, LEN(@strSortColumn))
END
ELSE
BEGIN
SET @SortTable = @Tables
SET @SortName = @strSortColumn
END
SELECT @type=t.name, @prec=c.prec
FROM sysobjects o
JOIN syscolumns c on o.id=c.id
JOIN systypes t on c.xusertype=t.xusertype
WHERE o.name = @SortTable AND c.name = @SortName
IF CHARINDEX('char', @type) > 0
SET @type = @type + '(' + CAST(@prec AS varchar) + ')'
DECLARE @strPageSize varchar(50)
DECLARE @strStartRow varchar(50)
DECLARE @strFilter varchar(1000)
DECLARE @strSimpleFilter varchar(1000)
DECLARE @strGroup varchar(1000)
/*默認當前頁*/
IF @CurrentPage < 1
SET @CurrentPage = 1
/*設置分頁參數.*/
SET @strPageSize = CAST(@PageSize AS varchar(50))
SET @strStartRow = CAST(((@CurrentPage - 1)*@PageSize + 1) AS varchar(50))
/*篩選以及分組語句.*/
IF @Filter IS NOT NULL AND @Filter != ''
BEGIN
SET @strFilter = ' WHERE ' + @Filter + ' '
SET @strSimpleFilter = ' AND ' + @Filter + ' '
END
ELSE
BEGIN
SET @strSimpleFilter = ''
SET @strFilter = ''
END
IF @Group IS NOT NULL AND @Group != ''
SET @strGroup = ' GROUP BY ' + @Group + ' '
ELSE
SET @strGroup = ''
/*執行查詢語句*/
EXEC(
'
DECLARE @SortColumn ' + @type + '
SET ROWCOUNT ' + @strStartRow + '
SELECT @SortColumn=' + @strSortColumn + ' FROM ' + @Tables + @strFilter + ' ' +
@strGroup + ' ORDER BY ' + @Sort + '
SET ROWCOUNT ' + @strPageSize + '
SELECT ' + @FIElds + ' FROM ' + @Tables + ' WHERE ' + @strSortColumn + @Operator
+ ' @SortColumn ' + @strSimpleFilter + ' ' + @strGroup + ' ORDER BY ' + @Sort + '
'
)
GO
<!--<![CDATA[]]>-->
</Content>
<Remarks>
<Remark PostUserName="guest" PostDateTime="2006-04-10 15:26:22">
<PostUserNickName>
訪客
</PostUserNickName>
<Content>
OK!
</Content>
</Remark>
<Remark PostUserName="test" PostDateTime="2006-04-10 09:18:35">
<PostUserNickName>
游客
</PostUserNickName>
<Content>
good
</Content>
</Remark>
<Remark PostUserName="dream" PostDateTime="2006-04-10 08:45:35">
<PostUserNickName>
dream
</PostUserNickName>
<Content>
不錯!
</Content>
</Remark>
<Remark PostUserName="no3" PostDateTime="2006-04-8 15:10:45">
<PostUserNickName>
夢幻3號
</PostUserNickName>
<Content>
看看
</Content>
</Remark>
<Remark PostUserName="admin" PostDateTime="2006-04-08 12:12:35">
<PostUserNickName>
</PostUserNickName>
<Content>
去試試
</Content>
</Remark>
<Remark PostUserName="Peter" PostDateTime="2006-03-15 16:12:35">
<PostUserNickName>
peterzb
</PostUserNickName>
<Content>
</Content>
</Remark>
</Remarks>
</Article>
</Articles>
xslt文檔[Article.xsl]
<?XML version="1.0" encoding="gb2312" ?>
<xsl:stylesheet version="1.0" XMLns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="Html" />
<xsl:template match="/">
<Html>
<head>
<meta http-equiv="Content-Type" content="text/Html; charset=GB2312" />
<title>
<xsl:value-of select="Articles/Article/Title" />
</title>
<link REL='Stylesheet' HREF='/web/resource/bbs.Css' TYPE='text/CSS' />
<style>
.title0 {font-size:17px;font-family:arial;font-weight:bold;text-decoration:none;color:#FFFFFF;}
A.title2:link {COLOR: #000000; TEXT-DECORATION: none}
A.title2:visited {COLOR: #000000; TEXT-DECORATION: none}
A.title2:active {COLOR: #ff0000; TEXT-DECORATION: none}
A.title2:hover {COLOR: #ff0000; TEXT-DECORATION: none}
DIV.post {
BORDER-RIGHT: #6e8bde 1px solid; BORDER-TOP: #6e8bde 1px solid; MARGIN-BOTTOM: 3px; BORDER-LEFT: #6e8bde 1px solid; BORDER-BOTTOM: #6e8bde 1px solid; BACKGROUND-COLOR: #f0eedf
}
DIV.postTitle {
PADDING-LEFT: 3px; FONT-WEIGHT: bolder; FONT-SIZE: 13px; PADDING-BOTTOM: 3px; PADDING-TOP: 3px; BORDER-BOTTOM: #6e8bde 1px dashed; BACKGROUND-COLOR: #d6dff7
}
DIV.postText {
PADDING-RIGHT: 10px; MARGIN-TOP: 10px; PADDING-LEFT: 10px; FONT-SIZE: 13px; MARGIN-BOTTOM: 10px; PADDING-BOTTOM: 5px; PADDING-TOP: 1px; BACKGROUND-COLOR: whitesmoke
}
</style>
</head>
<body>
<table width="800px" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="97">
<a href="/web/Article/ViewColumn.aspx?Colid=7" target="_blank">VB</a>/<a href="/web/Article/VIEwColumn.ASPx?Colid=11" target="_blank">
</td>
<td width="13%"><a href="/web/Article/VIEwColumn.aspx?Colid=12" target="_blank">ASP</a>/
<a href="/web/Article/VIEwColumn.aspx?Colid=13" target="_blank">ASP.Net</a>
</td>
<td width="13%">
<a href="/web/Article/VIEwColumn.ASPx?Colid=5" target="_blank">C#</a>
</td>
<td width="51">
<a href="/web/Article/VIEwColumn.ASPx?Colid=30" target="_blank">J#</a>
</td>
<td width="15%">
<a href="/web/Article/ViewColumn.aspx?Colid=20" target="_blank">ADO</a>/<a href="/web/Article/VIEwColumn.ASPx?Colid=21" target="_blank">
ADO.Net</a></td>
<td width="17%">
<a href="/web/Article/VIEwColumn.ASPx?Colid=9" target="_blank">Java</a>/<a href="/web/Article/VIEwColumn.ASPx?Colid=10" target="_blank">
Javascript</a></td>
<td width="11%">
<a href="/web/Article/VIEwColumn.ASPx?Colid=14" target="_blank">Html</a>/<a href="/web/Article/VIEwColumn.ASPx?Colid=15" target="_blank">
XML</a></td>
<td width="12%">
<a href="/web/default.ASPx" target="_blank">返回首頁</a></td>
</tr>
<tr>
<td width="97"><a href="/web/Article/VIEwColumn.ASPx?Colid=16" target="_blank">CSS</a></td>
<td><a href="/web/Article/ViewColumn.aspx?Colid=3" target="_blank">C</a>/<a href="/web/Article/VIEwColumn.ASPx?Colid=4" target="_blank">
C++</a></td>
<td><a href="/web/Article/VIEwColumn.ASPx?Colid=6" target="_blank">Delphi</a></td>
<td width="51">
<a href="/web/Article/VIEwColumn.ASPx?Colid=30" target="_blank">PHP</a></td>
<td>
<a href="/web/Article/VIEwColumn.ASPx?Colid=5" target="_blank">.Net</a></td>
<td>
<a href="/web/resource/CSDN/CSDN論壇精華.Html" target="_blank">CSDN論壇精華</a></td>
<td>
<a href="/web/Article/VIEwColumn.ASPx?Colid=19" target="_blank">Database</a></td>
<td><a href="#" onClick="Javascript:window.external.addFavorite('/web/Article.ASPx', 'Dream .Net')">加入收藏</a>
</td>
</tr>
<tr>
<td width="97">
<a href="/web/Note/notes.ASPx?function=all" target="_blank">GuestBook </a>
</td>
<td><a href="/web/bbs/bbs.ASPx">BBS</a>
</td>
<td><a href="/web/Article/VIEwColumn.ASPx?Colid=22" target="_blank">PowerBuilder</a></td>
<td width="51"></td>
<td><a href="/web/Article/VIEwColumn.ASPx?Colid=24" target="_blank"> Novel</a></td>
<td></td>
<td><A href="#" onclick="Javascript:window.external.addFavorite('/web/Article.ASPx', 'Dream .Net')">
</A>
</td>
<td>
<A href="mailto:web-network@163.com?subject=About Dream .Net Web System">聯系我們</A></td>
</tr>
<tr>
<td width="150px">
<a href="/web/Article/postArticle.ASPx"><img src="/web/images/post.gif" border="0" alt="【發表文章】" />【發表文章】</a>
</td>
<td width="200px" colspan="2">
<a href="/web/Article/postArticle.ASPx"><img src="/web/images/up.gif" border="0" alt="【上傳文章】" />【上傳文章】</a>
</td> </tr>
</table>
<table width="800px" border="0" cellpadding="0" cellspacing="0">
<xsl:apply-templates />
<tr>
<td align="center"><a href="Javascript:window.print()"><img src="/web/images/print.jpg" alt='【打印此文】' border="0" /></a>
<a href="Javascript:window.close();"><img src="/web/images/close.jpg" alt='【關閉窗口】' border="0" /></a>
</td>
</tr>
</table>
<table width="800px" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
<hr size="1" class="hrc" color="blue"></hr>
<table align="center" cellpadding="0" cellspacing="0" ID="Table1">
<tr>
<td>
<a href="/web/about.htm">網站簡介</a> <a href="/web/partner.htm">合伙伙伴</a> <a href="/web/map.htm">
網站地圖</a> <a href="/web/contract.ASPx">聯系方式</a><br></br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</Html>
</xsl:template>
<xsl:template match="Articles">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Article">
<tr>
<td height="25" align="left">
您當前所在位置為:<A href="/web/default.ASPx">首頁</A>--->
<A href="/web/Article/default.ASPx">
文章系統</A>--->
<xsl:element name="a">
<xsl:attribute name="href">
/web/Article/vIEwArticle.ASPx?ColID=<xsl:value-of select="ColumnID" />
<!--
<xsl:choose>
<xsl:when test="ColumnID='19'">
/web/Article/vIEwArticle.ASPx?ColID=19
</xsl:when>
<xsl:when test="ColumnID='5'">
/web/Article/vIEwArticle.ASPx?ColID=5
</xsl:when>
<xsl:otherwise>
/web/Article/vIEwArticle.ASPx?ColID=0
</xsl:otherwise>
</xsl:choose>
-->
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="ColumnName" />
</xsl:attribute>
<xsl:value-of select="ColumnName" />
</xsl:element>
---><xsl:value-of select="Title" /></td>
</tr>
<tr>
<td height="25" align="center">標題:<xsl:value-of select="Title" />
[點擊數:<xsl:value-of select="Dots" />]</td>
</tr>
<tr>
<td height="25" valign="top" align="center">作者:<xsl:value-of select="Author" />
[<xsl:value-of select="PostDateTime" />]</td>
</tr>
<tr>
<td height="25" valign="top" align="center">最近修改者:<xsl:value-of select="Editor" />
[<xsl:value-of select="EditDateTime" />]</td>
</tr>
<tr>
<td height="25" valign="top" align="center" class="WithBreaks">概述:<xsl:value-of select="Abstract" /></td>
</tr>
<tr>
<td height="25" valign="top" align="center">正文如下:</td>
</tr>
<tr>
<td><pre><xsl:value-of select="Content" /></pre></td>
</tr>
<xsl:apply-templates select="/Articles/Article/Remarks" />
</xsl:template>
<xsl:template match="Remarks">
<tr><td>
<table width="800px" border="0" cellpadding="0" cellspacing="0">
<th align="left"><h3>Feedback</h3></th>
<xsl:for-each select="Remark">
<div class="post">
<tr>
<div class="postTitle">
<td>
回復人:<b>
<font color="#3366CC">
<xsl:value-of select="@PostUserName" />
(<xsl:value-of select="PostUserNickName" />)
</font>
</b>
</td>
<td align="right">
<font color="#000000">
<xsl:value-of select="@PostDateTime" />
</font>
第<font color="red"><xsl:number value="position()" format="1"/></font>樓
</td>
</div>
</tr>
<tr>
<td colspan="2">
<div class="postText">
<xsl:value-of select="Content" />
</div>
</td>
</tr>
</div>
</xsl:for-each>
</table></td></tr>
</xsl:template>
</xsl:stylesheet>