📄 if-xpath-attribute.xtp
字号:
<s1 title="Default Attributes with XPath if()"><p>Since xsl:if can be cumbersome, Resin adds a special XPathfunction <var/if()/>. Although if() is not part of the XPath standard,it's expected that the next version of the standard will add it.<p><var/if()/> is like the Java conditional expression<var/test ? true : false/> pattern. In XPath, itlooks like <var/if(test,true,false)/>. Using if() can simplifystylesheets dramatically, especially in combination with attributevalue templates. Thefollowing is a simplification of the previous stylesheet using "example"as the default attribute value.</p><example title='default.xsl'><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="example"> <table class="if(@class,@class,'example')"> <tr> <td> <xsl:apply-templates/> </td> </tr> </table></xsl:template></xsl:stylesheet></example><p>Notice that the 'example' value needs to be quoted, otherwise itwould be interpreted as selecting an element value. The following XTPspecifies a different class for the example. Often, though, it's agood idea to stick with meaningful tags like <example> and leaveformatting questions like the CSS class to the stylesheet. In that case,you can use attributes to select different templates.</p><example title='hello.xtp'><example class="simple-example">This is an example.</example></example><results><table class="simple-example"><tr> <td>This is an example</td></tr></table></results><s2 title="Summary"><ul><li><var/if(expr,true_expr,false_expr)/> is a conditional expression.</ul></s2></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -