📄 modes.xtp
字号:
<s1 title="XSL Modes"><p>XSL modes are an advanced XSL feature. Some pages need to evaluatethe same XML twice. For example, a table of contents needs to createlists of the section titles, but the "normal" printing needs to outputthe section contents.<p>XSL adds <var/modes/> to process XML elements in different ways.If the stylesheet specifies the mode attribute in xsl:apply-templates,the XSL engine will only match templates with the matching mode.<p>The following example has two modes: the default mode and a"summary" mode. The summary mode is used to generate a table ofcontents. The <summary/> tag creates the table of contents. Itcalls xsl:apply-templates with the summary mode. The only template insummary mode is a section template. It will add items to the tableof contents.</p><example title='default.xsl'><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="section" mode="summary"> <li><xsl:value-of select="@title"/> <xsl:if test="section"> <ol><xsl:apply-templates mode="summary"/></ol> </xsl:if></li></xsl:template><xsl:template match="summary"><ol> <xsl:apply-templates select="../section" mode="summary"/></ol></xsl:template><template match="section"></template></xsl:stylesheet></example><p>To simplify the example, the template for <section> doesnothing. So only the summary will be generated from the XTP file.</p><example title='hello.xtp'><summary/><section title="First Section">Some text<section title="Subsection A">Subtext</section><section title="Subsection B">Subtext</section></section><section title="Second Section">Draft text</section></example><results><ol> <li>First Section <ol> <li>Subsection A</li> <li>Subsection B</li> </ol> </li> <li>Second Section</li></ol></results><s2 title="Strict XSL"><p>The StyleScript equivalent shows how to add arbitrary attributesin a StyleScript function. <var/foo/>=><var/bar/> will set the value<var/bar/> to the attribute <var/foo/>.</p><example title='default.xsl'>$template(section, mode=>summary) <<<li>$(@title) $if (section) << <ol>$apply-templates(mode=>summary);</ol> >></li>>>$template(summary) <<<ol> $apply-templates(../section, mode=>summary);</ol>>>$template(section) <<>></example></s2><s2 title="Summary"><ul><li><var/modes/> let stylesheets extract new formats from the same XML.<li><var/name=>value/> specifies named attributes in XTP.<li><var/$if/> conditionally evaluates part of a stylesheet.<li>The XPath pattern <var/../a/> selects all the siblings of a.</ul></s2></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -