📄 filter.xtp
字号:
<s1 title="XPath Filters"><p>XPath filters can match nodes matching a constraint expression, for exampleonly matching sections with titles. In the following example, sectionswith titles are formatted differently than sections without titles. UsingXPath filters, the stylesheet can use different templates to specify theformatting without using xsl:if.</p><example title='default.xsl'><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="section"> <xsl:apply-templates/></xsl:template><xsl:template match="section[@title]"> <h1> <xsl:value-of select="@title"/> </h1> <xsl:apply-templates/></xsl:template></example><p>A node may match more than one pattern. The full set of XSLT rulesto tell which pattern to use are fairly involved, but if thestylesheet always puts general patterns first and specific patternslast, the XSLT engine will select the later pattern. In the aboveexample, the filtered pattern "section[@title]" will match becauseit's more specific than "section". Even if the two patterns wereequally specific, the engine would select "section[@title]" becauseit's later in the stylesheet.</p><example title='hello.xtp'><section title="First Section">Some text</section><section>Section with no title</section></example><results><h1>First Section</h1>Some textSection with no title</results><s2 title="StyleScript"><p>The StyleScript translation is straightforward. The stylesheet justuses two templates, one with the filter pattern. Because StyleScriptexpands to XSL, the priority rules are exactly the same.</p><example title='default.xsl'>$template(section) <<$apply-templates();>>$template(section[@title]) <<<h1>$(@title)</h1>$apply-templates();>></example></s2><s2 title="Summary"><ul><li>The XPath pattern <var/a[b]/> selects <var/a/> only if <var/b/> exists.</ul></s2></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -