XSL簡單一實例

來源:互聯網
上載者:User

標籤:

利用xsl可以做到將資料和格式完全分離,下面比較一個xml+css和xml+xsl的區別。

 

XML + css

resume.xml檔案內容如下:

1 <?xml version="1.0" encoding="GB2312"?>2 <?xml-stylesheet type="text/css" href="resume.css"?> 3 <resume>  4 <name>禹希初</name>  5 <sex>男</sex>  6 <birthday>1977.5</birthday>  7 <skill>資料庫設計與維護、WEB開發</skill>  8 </resume>

resume.css檔案內容如下:

1 resume{ display: block;}2 name{ display: block; font-size:120%;}3 sex{ display:block; text-indent:2em}4 birthday{ display:block; text-indent:2em}5 skill{ display:block; text-indent:2em}

效果:

 

 

 

XML + xsl

resume.xml檔案內容如下:

1 <?xml version="1.0" encoding="GB2312"?>2 <?xml-stylesheet type="text/xsl" href="resume.xsl"?> 3 <resume>  4 <name>禹希初</name>  5 <sex>男</sex>  6 <birthday>1977.5</birthday>  7 <skill>資料庫設計與維護、WEB開發</skill>  8 </resume>

resume.xsl檔案內容如下:

 1 <?xml version="1.0" encoding="GB2312"?> 2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 3 <xsl:template match="/"> 4 <html> 5 <head>   6 <title>個人簡曆</title>   7 </head><body>   8 <xsl:for-each select="resume">   9 <p/>  10 <table border="1" cellspacing="0">  11 <caption style="font-size: 150%; font-weight: bold">  12 個人簡曆  13 </caption>  14 <tr>  15 <th>姓名</th><td><xsl:value-of select="name"/></td>  16 <th>性別</th><td><xsl:value-of select="sex"/></td>  17 <th>生日</th><td><xsl:value-of select="birthday"/></td>  18 </tr>  19 <tr>  20 <th>技能</th><td colspan="5"><xsl:value-of select="skill"/></td>  21 </tr>  22 </table>  23 </xsl:for-each>  24 </body> 25 </html>26 </xsl:template>27 </xsl:stylesheet>

效果:

 

參考:

http://justcoding.iteye.com/blog/778361

http://www.w3school.com.cn/xsl/xsl_for_each.asp

 

XSL簡單一實例

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.