博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

xsl基本语法

Posted on 2006-07-12 20:04  daniel-shen  阅读(546)  评论(0)    收藏  举报
声明:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
or
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
匹配:




<xsl:template match="/">
</xsl:template> 匹配嵌套:
<xsl:template match="/">
    <xsl:apply-templates/>
</xsl:template>
<xsl:template match="cd">
    <xsl:apply-templates select="title"/>     <xsl:apply-templates select="artist"/> </xsl:template>
<xsl:template match="title">
    do some thing!
</xsl:template>
<xsl:template match="artist">
    do some thing! </xsl:template> 从xml中取值:
<xsl:value-of select="catalog/cd/title"/>
排序:
<xsl:sort select="artist"/>//多用于循环中.eg:for-each中 条件测试1:
<xsl:if test="price &gt; 10">     do some thing!
</xsl:if>










条件测试2:相当于if...else...
<xsl:choose> <xsl:when test="price &gt; 10"> <td bgcolor="#ff00ff"> <xsl:value-of select="artist"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="artist"/></td> </xsl:otherwise> </xsl:choose>