⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attribute.xtp

📁 解压在c盘
💻 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 &lt;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 &lt;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'>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">&lt;xsl:template match="box">  &lt;table>    &lt;xsl:attribute name="class">      &lt;xsl:value-of select="@class"/>    &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>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 &lt;box> tag instead of creatingthe table directly.</p><example title='hello.xtp'>&lt;box class="example">This is an example.&lt;/box></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>The StyleScript equivalent for xsl:attribute uses <var/name/> as itsprimary argument.  The value of the attribute is definedwithin <var/&lt;&lt;...>>/> tags as usual.  The stylesheet shows howto combine text with the value-of expression.</p><example title='default.xsl'>$template(example) &lt;&lt;&lt;table>  $attribute("class") &lt;&lt;$(@class)>>&lt;tr>  &lt;td>    $apply-templates();  &lt;/td>&lt;/tr>&lt;/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 + -