if-attribute.xtp

来自「resinweb服务器源文件」· XTP 代码 · 共 84 行

XTP
84
字号
<s1 title="Default Attributes with xsl:if"><p>Often, elements should have a default attribute value if none isspecified in the XTP file.  An &lt;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 &lt;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'>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">&lt;xsl:template match="example">  &lt;table>    &lt;xsl:attribute name="class">      &lt;xsl:if test="@class">        &lt;xsl:value-of select="@class"/>      &lt;/xsl:if>      &lt;xsl:if test="not(@class)">example&lt;/xsl:if>    &lt;/xsl:attribute>    &lt;tr>      &lt;td>        &lt;xsl:apply-templates/>      &lt;/td>    &lt;/tr>  &lt;/table>&lt;/xsl:template>&lt;/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'>&lt;example>This is an example.&lt;/example></example><results>&lt;table class="example">&lt;tr>  &lt;td>This is an example&lt;/td>&lt;/tr>&lt;/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) &lt;&lt;&lt;table>  $attribute("class") &lt;&lt;    $if(@class) &lt;&lt;@class>>    $else &lt;&lt;example>>  >>&lt;tr>  &lt;td>    $apply-templates();  &lt;/td>&lt;/tr>&lt;/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 + =
减小字号Ctrl + -
显示快捷键?