📄 xslt-fun.xtp
字号:
<xsl:attribute-set name='font'> <xsl:attribute name='font-size'>12pt</xsl:attribute> <xsl:attribute name='font-weight'>bold</xsl:attribute></xsl:attribute-set><xsl:template match='a'> <c xsl:use-attribute-sets='font'/></xsl:template></example><results><c font-size='12pt' font-weight='bold'/></results></s2><s2 name="pi" title="<xsl:processing-instruction>" type="defun"><p>Creates a new processing instruction.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>name</td><td>Processing instruction name.</td></tr></deftable><example><xsl:template match='a'> <xsl:processing-instruction name='foo'> <xsl:text>Text for the PI</xsl:text> </xsl:processing-instruction/></xsl:template></example><results><?foo Text for the PI?></results></s2><s2 name="comment" title="<xsl:comment>" type="defun"><p>Creates a new comment.</p> <p>The contents of the xsl:comment elementbecome the contents of the comment.</p><example><xsl:template match='a'> <xsl:comment> <xsl:text>Text for the comment</xsl:text> </xsl:processing-instruction/></xsl:template></example><results><!--Text for the comment--></results></s2><s2 name="copy" title="<xsl:copy>" type="defun"><p>Copies the current node, but not children or attributes, to theoutput.</p> <p>To copy an element, a stylesheet must copy the attributes as well.</p><p>The following example is the identity stylesheet. It copies inputto the output including the attributes.</p><example><xsl:template match='@*|node()'> <xsl:copy> <xsl:apply-templates select='@*|node()'/> </xsl:copy></xsl:template></example></s2><s2 name="copy-of" title="<xsl:copy-of .../>" type="defun"><p>Copies a sub-tree into the output.</p> <p><code>copy-of</code> resembles<code>value-of</code>. <code>value-of</code> always converts the value to astring. <code>copy-of</code> will copy subtrees. </p><deftable><tr><th>attribute</th><th>meaning</th></tr><tr><td>select</td><td>An XPath expression to be copied.</td></tr></deftable></s2><s2 name="variable" title="<xsl:variable>" type="defun"><p>Assignes an XSL variable.</p> <p>Variables can be retrieved usingthe XPath variable syntax.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>name</td><td>variable name</td></tr><tr><td>select</td><td>variable value</td></tr></deftable><example><xsl:variable name='foo' select='1+1'/><xsl:template match='a'> <xsl:value-of select='$foo'/></xsl:template></example><results>2</results></s2><s2 name="call-template" title="<xsl:call-template>" type="defun"><p>Calls a named template with the current node.</p><p><code>xsl:call-template</code> lets stylesheets reuse common code, likefunctions. It works like <code>xsl:apply-templates select='.'</code>except that it calls based on a template name.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>name</td><td>template name to call</td></tr><tr><td>mode</td><td>template mode</td></tr></deftable></s2><s2 name="param" title="<xsl:param>" type="defun"><p>Declares an XSL parameter.</p> <p><code>xsl:param</code>'s<code>select</code> parameter as a default. If the variable has beenassigned, it uses the old value.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>name</td><td>variable name</td></tr><tr><td>select</td><td>variable value</td></tr></deftable><example><xsl:template name='fun'> <xsl:param name='foo' select='15'/> <xsl:value-of select='$foo'/></xsl:template><xsl:template match='a'> <xsl:call-template name='foo'> <xsl:with-param name='foo' select='1+2'/> </xsl:call-template></xsl:template></example><results>3</results></s2><s2 name="apply-imports" title="<xsl:apply-imports>" type="defun"><p>Like Java's <code>super</code>, calls the overridden template.</p></s2><s2 name="sort" title="<xsl:sort>" type="defun"><p>Sorts nodes in xsl:apply-templates orxsl:for-each.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>select</td><td>value to sort on (default = '.')</td></tr><tr><td>order</td><td>ascending or descending (default = ascending)</td></tr><tr><td>data-type</td><td>text or number (default = text)</td></tr></deftable><note>case-order and lang attributes are not implemented</note></s2><s2 name="choose" title="<xsl:choose ...> ..." type="defun"><p>Implements an if-elsif-else block.</p> <p>The <code>xsl:when</code>statements are tested in order. The first matching one is executed.If none match, the <code>xsl:otherwise</code> block is executed.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>test</td><td>XPath expression evaluating to a boolean.</td></tr></deftable><example><xsl:template match='a'> <xsl:choose> <xsl:when test='@color="red"'> <xsl:text>stop</xsl:text> </xsl:when> <xsl:when test='@color="green"'> <xsl:text>go</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>yield</xsl:text> </xsl:otherwise> </xsl:choose></xsl:template></example></s2></s1><s1 name="xsl" title="Resin extensions"><!--<defun name=copy-element title='<xtp:copy-element>' version='resin1.0'><p>Copies the element to the output.</p><p><code/xtp:copy-element/> is extremely useful as a default rule.With <code/xtp:copy-element/> as the default, the input gets copied tothe output. Using the usual default, all tags get stripped.</p><p>The standard default rule produces the following,</p><example><a>A text</a><b>B text</b></example><results>A textB text</results><p>Using <code/xtp:copy-element/>, XSL stylesheets can copy elementsit doesn't understand.</p><example><xsl:template match='*'> <xtp:copy-element> <xsl:apply-templates/> </xtp:copy-element></xsl:template></example><example><a>A text</a><b>B text</b></example><results><a>A text</a><b>B text</b></results></defun>--><s2 name="expression" title="<xtp:expression>expression ..." version="resin1.0" type="defun"><p>Executes <var>expression</var> and prints it to the output.</p><p> Stylesheets can use any JavaScript expression. The followingvariables are pre-defined in stylesheets.</p><deftable><tr><th>Variable</th><th>Meaning</th></tr><tr><td>node</td><td>The current org.w3c.dom.Node.</td></tr><tr><td>out</td><td>The com.caucho.xsl.XslWriter.</td></tr></deftable><p>In addition, the <var>out</var> variable gives access to the servletPageContext with the <var>page</var> property.</p><example><xsl:template match='welcome-user'> <xsl:text>Welcome back, </xsl:text> <xtp:expression> out.page.session.value.user <xtp:expression></xsl:template></example></s2><s2 name="scriptlet" title="<xtp:scriptlet> statement_list" version="resin1.0" type="defun"><p>Executes the <var>statement_list</var> scriptlet.</p> <p> The JavaScript code can be any statement list. The same implicitvariables are allowed in scriptlets as in expressions.</p><p>The following example creates a number of stars:</p><example><@# page language='javascript' #><xsl:template match='ct:stars'> <xtp:scriptlet> for (var i = 0; i < node.attribute.count; i++) out.write('*'); </xtp:scriptlet></xsl:template></example><example>1 = <ct:stars count='1'/>9 = <ct:stars count='9'/></example><results>1 = *9 = *********</results></s2><s2 name="declaration" title="<xtp:declaration>" index="declaration" type="defun"><p>Adds declaration code, i.e. code outside of any function.</p><example><xtp:declaration>function dist(x1, y1, x2, y2){ return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));}</xtp:declaration></example></s2><s2 name="page" title="<xtp:directive.page attributes />" type="defun"><p>Sets page directives</p><deftable><tr><th>name</th><th>meaning</th></tr><tr><td>language</td><td>script language, default Java</td></tr><tr><td>session</td><td>use sessions, default false</td></tr><tr><td>errorPage</td><td>page to display for errors</td></tr><tr><td>errorPage</td><td>page to display for errors</td></tr><tr><td>import</td><td>imports Java packages </td></tr><tr><td>contentType</td><td>content-type of the generated page</td></tr></deftable></s2><!--<defun name=cache title='<xtp:directive.cache attributes/>'><p>Caches the generated JSP file by default.</p><p>Caching for XSL is more complicated than for JSP because only sometemplates may be used in a page. Caching is based on the generatedpage, not simply on the stylesheet.</p><p>A page that just uses statictemplates is automatically cached. Pages that use scripts just forsimple calculation can also be cached. But pages that use scriptsbased on the request cannot be cached.</p><deftable><tr><th>name<th>meaning<tr><td>file<td>the JSP file depends on <var/file/>.<tr><td>no-cache<td>do not cache the generated JSP.</deftable></defun>--></s1> </body></document>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -