📄 if-attribute.xtp
字号:
<s1 title="Default Attributes with xsl:if"><p>Often, elements should have a default attribute value if none isspecified in the XTP file. An <example> tag might have a default CSSclass of "example", but let the XTP change the default. In a template,xsl:if will conditionally produce XML depending on an XPath expression.<p>The following example adds the class attribute to the tabledepending on the class value in the <box> element. If the XTP filespecifies the class, the stylesheet will use it. The the XTP file doesn'tspecify the class, the stylesheet will use "example" as a default.</p><example title='default.xsl'><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="example"> <table> <xsl:attribute name="class"> <xsl:if test="@class"> <xsl:value-of select="@class"/> </xsl:if> <xsl:if test="not(@class)">example</xsl:if> </xsl:attribute> <tr> <td> <xsl:apply-templates/> </td> </tr> </table></xsl:template></xsl:stylesheet></example><p>The example XTP does not specify class, so the stylesheet willuse "example" as the default class.</p><example title='hello.xtp'><example>This is an example.</example></example><results><table class="example"><tr> <td>This is an example</td></tr></table></results><s2 title="StyleScript"><p>StyleScript's $if uses the test expression for its first argument.If the expression is true, the block is used as a value. If false,the block after the $else will be used for the value.</p><example title='default.xsl'>$template(example) <<<table> $attribute("class") << $if(@class) <<@class>> $else <<example>> >><tr> <td> $apply-templates(); </td></tr></table>>></example></s2><s2 title="Summary"><ul><li><var/xsl:if/> evaluates conditionally.<li><var/not(expr)/> negates a boolean.</ul></s2></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -