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

📄 xslt-fun.xtp

📁 RESIN 3.2 最新源码
💻 XTP
📖 第 1 页 / 共 2 页
字号:
<document>  <header>    <product>resin</product>    <title>XSLT Extensible Stylesheet Language</title>    <keywords>      <keyword>xslt</keyword>    </keywords>    <description>      <p>The extensible stylesheet language is a language for transforming XML        documents to new XML documents.  It's based on matching        elements in the XML tree and replacing the element with new        XML.  For example, replacing a 'definition' tag with an HTML        table with a silver background.</p>    </description>  </header>  <body>    <localtoc/><s1 title="Introduction"><p>XSLT processes the input document recursively from the top down,essentially a depth first traversal of the tree.  When itexamines each node, it finds the best match from all the <ahref="#template">templates</a>.  XSLT then follows the processinginstructions for the matching template, usually adding text to theoutput.</p><p>If XSLT cannot find a matching template, it applies default rules.Text gets copied to the output.  The children of elements areprocessed, but the elements themselves are not copied.  So acompletely blank XSLT stylesheet will remove all the tags and justprint out the text.</p><p>When it's done with the current node, XSLT moves to the next oneuntil the entire input tree is complete.</p><p>For example, it might process an HTML file in the following order:</p><ol><li>HTML</li><li>HEAD</li><li>TITLE</li><li>META</li><li>BODY</li><li>P</li><li>TEXT</li><li>etc</li></ol><p>      Resin's XSLT follows the 1.0 W3C specification.      </p></s1><s1 name="xslt-core" title="XSLT core"><s2 name="template" title="&lt;xsl:stylesheet&gt;" type="defun"><p>The top-level element of an XSL stylesheet.</p></s2><s2 name="template" title="&lt;xsl:template ... &gt; ..." type="defun"><p>Establishes a pattern and replacement text.</p><p><code>xsl:template</code> registers its pattern with the XSL processingengine.  When a node matches the pattern, XSL will process thecontents of the template.</p><p>Pure XSL processes the contents slightly differently than XTP.  XSLexpects all tags to be valid XML.  XTP is more forgiving.  If the tag is notone of those defined by XSL, it will treat the tag as raw text.</p><deftable><tr><th>attribute</th><th>meaning</th></tr><tr><td>match</td><td>the XPath match pattern (required)</td></tr><tr><td>mode</td><td>string grouping templates into a special mode</td></tr><tr><td>name</td><td>Name for later use by xsl:call-template</td></tr><tr><td>priority</td><td>conflict-resolving priority, an integer</td></tr></deftable><p>In the following example, the template matches any 'box' tag.  Thecontents of the box are placed in a centered table 80% of the currentwidth.</p><p>This example is legal in XTP because the &lt;td&gt; and &lt;tr&gt;are treated as raw text.  The example is illegal in XSL because thosetags are missing their close tags.</p><example>&lt;xsl:template match='box'&gt;  &lt;center&gt;  &lt;table width='80%'&gt;  &lt;tr&gt;&lt;td&gt;    &lt;xsl:apply-templates/&gt;  &lt;/td&gt;&lt;/tr&gt;  &lt;/table&gt;  &lt;/center&gt;&lt;/xsl:template&gt;</example><example>&lt;p&gt;Here's a boxed quote,&lt;/p&gt;&lt;box&gt;To be or not to be...&lt;/box&gt;</example><results>&lt;p&gt;Here's a boxed quote,&lt;/p&gt;&lt;center&gt;&lt;table width='80%'&gt;&lt;tr&gt;&lt;td&gt;  To be or not to be...&lt;/table&gt;&lt;/center&gt;</results></s2><s2 name="apply-templates" title="&lt;xsl:apply-templates ... &gt; ..." type="defun"><p>Evaluates the children of the current node.</p><p><code>xsl:apply-templates</code> recursively processes the children.  If atemplate has no <code>xsl:apply-templates</code>, then the children areignored.</p><deftable><tr><th>attribute</th><th>meaning</th></tr><tr><td>select</td><td>An XPath select pattern selecting the nodes toevaluate next. (optional)</td></tr><tr><td>mode</td><td>only selects templates with the given <var>mode</var></td></tr></deftable><p>The first example doubles the contents by calling<code>xsl:apply-templates</code> twice.</p><example>&lt;xsl:template match='double'&gt;  &lt;xsl:apply-templates/&gt;  &lt;xsl:apply-templates/&gt;&lt;/xsl:template&gt;</example><example>&lt;double&gt;Some &lt;foo/&gt; text.&lt;/double&gt;</example><results>Some &lt;foo/&gt; text.Some &lt;foo/&gt; text.</results><p>The <code>select</code> pattern can restrict the children to evaluate.Stylesheets can use it to select elements and to reorder them.</p><p>The following example writes the 'a' nodes followed by the 'b'nodes and ignores everything else.</p><example>&lt;xsl:template match='a-b-test'&gt;  &lt;xsl:apply-templates select='a'/&gt;  &lt;xsl:apply-templates select='b'/&gt;&lt;/xsl:template&gt;</example><example>&lt;a-b-test&gt;  Junk Text.  &lt;b/&gt;  &lt;a&gt;    Good text.  &lt;/a&gt;  More Junk.  &lt;b&gt;    Some B text.  &lt;/b&gt;  &lt;a&gt;    More Good text.  &lt;/a&gt;&lt;/a-b-test&gt;</example><results>&lt;a&gt;  Good text.&lt;/a&gt;&lt;a&gt;  More Good text.&lt;/a&gt;&lt;b/&gt;&lt;b&gt;  Some B text.&lt;b&gt;</results></s2><s2 name="text" title="&lt;xsl:text&gt; ..." type="defun"><p>Writes the contents to the output.</p>  <p><code>xsl:text</code> isuseful when you need to force spacing or special text.  Usually,Resin will produce the text you expect.  <code>xsl:text</code> is therefor the strange cases when you need full control.</p></s2><s2 name="value-of" title="&lt;xsl:value-of .../&gt;" type="defun"><p>Writes a calculated value output.</p>  <deftable><tr><th>attribute</th><th>meaning</th></tr><tr><td>select</td><td>An XPath expression to be printed.</td></tr></deftable><p><code>value-of</code> is particularly useful for extracting attributevalues.  The following example creates a JSP tag which adds twonumbers.</p><example>&lt;xsl:template match='ct:sum'&gt;&lt;jsp:expression&gt;&lt;xsl:value-of select='@a'&gt; + &lt;xsl:value-of select='@b'&gt;&lt;/jsp:expression&gt;&lt;/xsl:template&gt;</example></s2><s2 name="for-each" title="&lt;xsl:for-each ...&gt; ..." type="defun"><p>Loops over child select patterns.</p>  <p><code>xsl:foreach</code>gives stylesheets complete control over the actions for child nodes.</p><p>Usually, stylesheets will want to use the full pattern matchingcapability given by XSL.  Sometimes the specific structure is known,like sections in a chapter.  When generating a table of contents, itmay be easier to scan over the sections.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>select</td><td>XPath select pattern</td></tr></deftable><example>&lt;xsl:template match='contents'&gt;  &lt;ol&gt;  &lt;xsl:for-each select='section'&gt;    &lt;li&gt;&lt;xsl:value-of select='@title'/&gt;&lt;/li&gt;  &lt;/xsl:for-each&gt;  &lt;/ol&gt;&lt;/xsl:template&gt;</example></s2><s2 name="if" title="&lt;xsl:if ...&gt; ..." type="defun"><p>Evaluates the containing content if an expression evaluates totrue.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>test</td><td>XPath expression evaluating to a boolean.</td></tr></deftable></s2><s2 name="import" title="&lt;xsl:import .../&gt;" type="defun"><p>Imports a stylesheet.</p>  <p><code>xsl:import</code> lets stylesheetsborrow from each other.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>href</td><td>Path to the imported stylesheet</td></tr></deftable></s2><s2 name="output" title="&lt;xsl:output .../&gt;" type="defun"><p>Control the output printing.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>method</td><td>xml or html or text.  Select printing method</td></tr><tr><td>version</td><td>XML version</td></tr><tr><td>encoding</td><td>character set to print the results</td></tr><tr><td>omit-xml-declaration</td><td>skip the XML or HTML declaration</td></tr><tr><td>indent</td><td>pretty-print or not</td></tr><tr><td>media-type</td><td>mime-type</td></tr><tr><td>disable-output-escaping</td><td>'&lt;' gets printed as '&lt;', not '&amp;lt;'</td></tr></deftable></s2></s1><s1 name="xslt" title="XSLT"><s2 name="element" title="&lt;xsl:element&gt;" type="defun"><p>Creates a new element.</p>  <p>The name can be computed using an attribute value template.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>name</td><td>Name of the new element.</td></tr></deftable><example>&lt;xsl:template match='a'&gt;  &lt;xsl:element name='b{@id}'&gt;    &lt;c/&gt;  &lt;/xsl:element&gt;&lt;/xsl:template&gt;</example><results>&lt;b3&gt;&lt;c/&gt;&lt;/b3&gt;</results></s2><s2 name="attribute" title="&lt;xsl:attribute&gt;" type="defun"><p>Adds an attribute to the element.</p>  <p>The name can be computed using an attribute value template.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>name</td><td>Name of the new attribute.</td></tr></deftable><example>&lt;xsl:template match='a'&gt;  &lt;c&gt;    &lt;xsl:attribute name='b{@id}'&gt;    &lt;xsl:value-of select='c{@id}'/&gt;    &lt;/xsl:attribute&gt;  &lt;/c&gt;&lt;/xsl:template&gt;</example><results>&lt;c b3='c3'/&gt;</results></s2><s2 name="attribute-set" title="&lt;xsl:attribute-set&gt;" type="defun"><p>Defines a named attribute set.</p>  <p>The attributes in the set are defined by xsl:attribute elements.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>name</td><td>Name of the attribute set.</td></tr></deftable><example>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -