时间: 2021-07-31 作者:daque
七. xsl 的遏制语句1.前提语句if...thenxsl同样再有前提语句(呵呵~~好利害吧,象步调谈话一律)。简直的语法是减少一个xsl:if元素,一致如许<xsl:if match=".[artist='bob dylan']">... some output ...</xsl:if>
上头的例子改写变成:<?xml version='1.0'?><xsl:stylesheet xmlns:xsl="http://www.w3.org/tr/wd-xsl"><xsl:template match="/"><html><body><table border="2" bgcolor="yellow"><tr><th>title</th><th>artist</th></tr><xsl:for-each select="catalog/cd"><xsl:if match=".[artist='bob dylan']"><tr><td><xsl:value-of select="title"/></td><td><xsl:value-of select="artist"/></td></tr></xsl:if></xsl:for-each></table></body></html></xsl:template></xsl:stylesheet>
2. xsl 的choosechoose的用处是展示多个前提,给出各别表露截止。简直的语法是减少一组xsl:choose,xsl:when,xsl:otherwise元素:
<xsl:choose><xsl:when match=".[artist='bob dylan']">... some code ...</xsl:when><xsl:otherwise>... some code ....</xsl:otherwise></xsl:choose>
上头的例子改写变成:<?xml version='1.0'?><xsl:stylesheet xmlns:xsl="http://www.w3.org/tr/wd-xsl"><xsl:template match="/"><html><body><table border="2" bgcolor="yellow"><tr><th>title</th><th>artist</th></tr><xsl:for-each select="catalog/cd"><tr><td><xsl:value-of select="title"/></td><xsl:choose><xsl:when match=".[artist='bob dylan']"><td bgcolor="#ff0000"><xsl:value-of select="artist"/></td></xsl:when><xsl:otherwise><td><xsl:value-of select="artist"/></td></xsl:otherwise></xsl:choose></tr></xsl:for-each></table></body></html></xsl:template></xsl:stylesheet>