📄 attribute.xtp
字号:
<s1 title="xsl:attribute"><p>Stylesheets can calculate attributes using <var/xsl:attribute/>. Wherexsl:value-of creates text, xsl:attribute creates attributes. The contents ofthe xsl:attribute element will become the value of the attribute. Thisdiffers from xsl:value-of which uses a select pattern to create text.Typically, the contents of an xsl:attribute will be a combination oftext and xsl:value-of elements.</p><p>The following example creates a useful tag, the <box> tag.The contents of the tag are placed in an HTML table to format a box. TheCSS style of the table is specified by an attribute in the source XTP. Tagslike <box> are very useful examples of XSL. Instead of hard-coding HTMLtables in a JSP file, the page can specify boxes. If the site wants tochange the look, it's simple to change the stylesheet and modify the entiresite at once.</p><example title='default.xsl'><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="box"> <table> <xsl:attribute name="class"> <xsl:value-of select="@class"/> </xsl:attribute> <tr> <td> <xsl:apply-templates/> </td> </tr> </table></xsl:template></xsl:stylesheet></example><p>As mentioned above, the xsl:attribute uses xsl:value-of to compute thevalue of the <var/@class/> attribute. The results below shows how mucheasier the XTP file will be when you use a <box> tag instead of creatingthe table directly.</p><example title='hello.xtp'><box class="example">This is an example.</box></example><results><table class="example"><tr> <td>This is an example</td></tr></table></results><s2 title="StyleScript"><p>The StyleScript equivalent for xsl:attribute uses <var/name/> as itsprimary argument. The value of the attribute is definedwithin <var/<<...>>/> tags as usual. The stylesheet shows howto combine text with the value-of expression.</p><example title='default.xsl'>$template(example) <<<table> $attribute("class") <<$(@class)>><tr> <td> $apply-templates(); </td></tr></table>>></example></s2><s2 title="Summary"><ul><li>Tags in stylesheets are parsed, not raw text. So you can add attributesto elements.<li><var/xsl:attribute name="my-name">/> adds an attribute to thecurrent element.<li><var/$attribute(my-name)/> expands to <var/xsl:attribute name="my-name"/>.</ul></s2></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -