📄 copy.xtp
字号:
<s1 title="Copying nodes and attributes"><p>Stylesheets can use xsl:copy to copy nodes from the XTP file tothe generated HTML. The most common use of xsl:copy creaes a defaultrule to copy the input to the output, i.e. the identity transformation.<p>In the previous examples, the default rule omittedunknown elements. For most XTP pages, a better default rule copiesthe input to the output. That way the page can use XTP as littleas it wants and mix and match JSP and HTML with custom tags.<p>The following example creates a default identity pattern and asingle custom tag. The match pattern "*|@*" matches any element (the "*")and any attribute (the "@*"). The vertical bar is a union operator.The node is copied using xsl:copy and the contents apply thestylesheet recursively.<p>xsl:apply-templates has an optional select pattern. The selectednodes will have the stylesheet recursively applied. The defaultpattern selects all children nodes. The identity template needs toselect children nodes and attribute nodes. "node()" selects any childnodes and "@*" selects attributes.</p><example title='default.xsl'><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="*|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy></xsl:template><xsl:template match="hello"> <xsl:text>Hello</xsl:text></xsl:template></xsl:stylesheet></example><example title='hello.xtp'>Testing <font color="red"><hello/></font></example><results><html><body>Testing <font color="red">Hello</font></body></html></results><s2 title="StyleScript"><p>The StyleScript equivalent for $apply-templates uses the select attribute asits first parameter. $copy acts like any typical element.</p><example title='default.xsl'>$template(*|@*) << $copy << $apply-templates(node()|@*); >>>>$template(hello) <<Hello>></example></s2><s2 title="Summary"><ul><li>The XPath pattern <var/*/> matches any element.<li>The XPath pattern <var/@*/> matches any attribute.<li>The XPath pattern <var/a|b/> matches pattern <var/a/> or <var/b/><li><var/xsl:copy/> copies XML nodes to the output.<li><var/xsl:apply-templates/> can select the nodes to evaluate.<li>XTP pages are parsed as HTML, automatically expanding optional tags, like<var/html/> and <var/body/>.<li>Specific templates override general templates.<li>Later templates override earlier ones.<li><var/$copy/> expands to <var/xsl:copy/><li><var/$apply-templates(foo)/> expands to <var/<xsl:apply-templates select="foo"/>/></ul></s2></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -