Simple use of XSLT [xml-->html]

Source: Internet
Author: User
Tags abstract filter format end sql net sort table name
Xml

XSLT command [XML format conversion]
1. Cycle <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. Sort <xsl:sort...>
3. Conditional processing <xsl:if...> or <xsl:choose...> or <xsl:when...>
4. Name Template
<xsl:template name...<xsl:template name...>,<xsl:param...>
<xsl:with-param...>,<xsl:call-template...>
5. Numbering method <xsl:number value format...>

XML document [Article.xml] <?xml version= "1.0" encoding= "gb2312"?>
<?xml-stylesheet type= ' text/xsl ' href= ' article.xsl '?>
<Articles>
<Article>
<ArticleID>2897</ArticleID>
<title>[sharing] Tens of thousands of levels of paging stored procedures (with effect demo) </Title>
<Author> Network </Author>
<abstract>[sharing] Tens of thousands of levels of paging stored procedures (with effect demo) </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> Network </Editor>
<editdatetime>2006-02-27 18:29:53</editdatetime>
<Content>
[Sharing] Tens of thousands of levels of paging stored procedures (with effect demo) effect Demo:
Http://www.cn5135.com/_App/Opportunities/QueryResult.aspx
CREATE PROCEDURE cn5135_sp_pagination
/******************************************************************
Tens of millions of levels of paging stored procedures
*******************************************************************
Parameter description:
1.Tables: Table name, view
2.PrimaryKey: Primary keyword
3.Sort: Sort statements without ORDER by example: NewsID desc,orderrows ASC
4.CurrentPage: Current page number
5.PageSize: Paging Size
6.Filter: Filter statements, without where
7.group:group statement without Group by
Effect Demo: http://www.cn5135.com/_App/Opportunities/QueryResult.aspx
***************************************************************/
(
@Tables varchar (1000),
@PrimaryKey varchar (100),
@Sort varchar = NULL,
@CurrentPage int = 1,
@PageSize int = 10,
@Fields varchar (1000) = ' * ',
@Filter varchar (1000) = NULL,
@Group varchar (1000) = NULL
)
As
/* Default sort */
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
/* Set the sort statement. * *
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)
/* Default Current Page * *
IF @CurrentPage < 1
SET @CurrentPage = 1
/* Set Paging parameters. * *
SET @strPageSize = CAST (@PageSize as varchar (50))
SET @strStartRow = CAST ((@CurrentPage-1) * @PageSize + 1) as varchar (50))
/* Filter and GROUP statements. * *
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 = '
/* Execute Query statement * *
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>
Visitors
</PostUserNickName>
<Content>
Ok!
</Content>
</Remark>
<remark postusername= "test" postdatetime= "2006-04-10 09:18:35" >
<PostUserNickName>
Tourists
</PostUserNickName>
<Content>
Good
</Content>
</Remark>
<remark postusername= "Dream" postdatetime= "2006-04-10 08:45:35" >
<PostUserNickName>
Dream
</PostUserNickName>
<Content>
Not bad!
</Content>
</Remark>
<remark postusername= "NO3" postdatetime= "2006-04-8 15:10:45" >
<PostUserNickName>
Dream Number 3rd
</PostUserNickName>
<Content>
Look
</Content>
</Remark>
<remark postusername= "admin" postdatetime= "2006-04-08 12:12:35" >
<PostUserNickName>

</PostUserNickName>
<Content>
Give it a try.
</Content>
</Remark>
<remark postusername= "Peter" postdatetime= "2006-03-15 16:12:35" >
<PostUserNickName>
Peterzb
</PostUserNickName>
<Content>

</Content>
</Remark>
</Remarks>
</Article>
</Articles>
XSLT document [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= "/" >
<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>
<body>
<table width= "800px" border= "0" cellpadding= "0" cellspacing= "0" >
<tr>
&LT;TD width= ">"
<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>
&LT;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>
&LT;TD width= "13%" >
<a href= "/web/article/viewcolumn.aspx? Colid=5 "target=" _blank ">C#</a>
</td>
&LT;TD width= "Wuyi" >
<a href= "/web/article/viewcolumn.aspx? Colid=30 "target=" _blank ">J#</a>
</td>
&LT;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>
&LT;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>
&LT;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>
&LT;TD width= "12%" >
<a href= "/web/default.aspx" target= "_blank" > Return home </a></td>
</tr>
<tr>
&LT;TD width= "><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>
&LT;TD width= "Wuyi" >
<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 Forum essence. html" target= "_blank" >csdn Forum essence </a></td>
<td>
<a href= "/web/article/viewcolumn.aspx? colid=19 "target=" _blank ">Database</a></td>
<td><a href= "#" > Add to Favorites </a>
</td>
</tr>
<tr>
&LT;TD width= ">"
<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>
&LT;TD width= "Wuyi" ></td>
<td><a href= "/web/article/viewcolumn.aspx? colid=24 "target=" _blank "> novel</a></td>
<td></td>
<td><a href= "#" >
</A>
</td>
<td>
<a href= "Mailto:web-network@163.com?subject=about Dream. NET Web System" > Contact Us </A></td>
</tr>
<tr>
&LT;TD width= "150px" >
<a href= "/web/article/postarticle.aspx" > "Publish article" </a>
</td>
&LT;TD width= "200px" colspan= "2" >
<a href= "/web/article/postarticle.aspx" > "Upload article" </a>
</td> </tr>
</table>
<table width= "800px" border= "0" cellpadding= "0" cellspacing= "0" >
<xsl:apply-templates/>
<tr>
&LT;TD align= "center" ><a href= "Javascript:window.print ()" ></a>
<a href= "Javascript:window.close ();" ></a>
</td>
</tr>
</table>
<table width= "800px" border= "0" cellpadding= "0" cellspacing= "0" >
<tr>
&LT;TD valign= "Top" >
&LT;HR size= "1" class= "HRC" color= "Blue" ><table align= "center" cellpadding= "0" cellspacing= "0" id= "Table1" >
<tr>
<td>
<a href= "/web/about.htm" > website Profile </a> | <a href= "/web/partner.htm" > Partner </a> | <a href= "/web/map.htm" >
Site Map </a> | <a href= "/web/contract.aspx" > Contact Way </a><br></br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</xsl:template>
<xsl:template match= "articles" >
<xsl:apply-templates/>
</xsl:template>
<xsl:template match= "Article" >
<tr>
&LT;TD height= "align=" "Left" >
Your current location is: <a href= "/web/default.aspx" > Home </A>--->
<a href= "/web/article/default.aspx" >
Article System </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= '" >
/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>
&LT;TD height= "align=" "Center" > Title: <xsl:value-of select= "title"/>
[Number of clicks: <xsl:value-of select= "Dots"/>]</td>
</tr>
<tr>
&LT;TD height= "valign=" "Top" align= "center" > Author: <xsl:value-of select= "Author"/>
[<xsl:value-of select= "Postdatetime"/>]</td>
</tr>
<tr>
&LT;TD height= "valign=" "Top" align= "center" > recently modified by: <xsl:value-of select= "Editor"/>
[<xsl:value-of select= "Editdatetime"/>]</td>
</tr>
<tr>
&LT;TD height= "valign=" "Top" align= "center" class= "Withbreaks" > Overview: <xsl:value-of select= "Abstract"/>< /TD>
</tr>
<tr>
&LT;TD height= "valign=" "Top" align= "center" > text as follows:</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" ><xsl:for-each select= "Remark" >
<div class= "POST" >
<tr>
<div class= "Posttitle" >
<td>
Reply Person:<b>
<font color= "#3366CC" >
<xsl:value-of select= "@PostUserName"/>
(<xsl:value-of select= "Postusernickname"/>)
</font>
</b>
</td>
&LT;TD align= "Right" >
<font color= "#000000" >
<xsl:value-of select= "@PostDateTime"/>
</font>
Section <font color= "red" ><xsl:number value= "position ()" format= "1"/></font> floor
</td>
</div>
</tr>
<tr>
&LT;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>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.