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">
VBScript</a>
</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>
xslt的简单使用[xml-->html]
最新推荐文章于 2021-06-09 18:49:20 发布