📄 hello.xtp
字号:
<s1 title="XTP Hello, World"><p>XSL is a pattern matching language like Prolog. It looks at XML nodes oneby one and checks the stylesheet for matching patterns. XSL uses XPath asthe pattern-matching language. Like Prolog, each XSL "rule" has a matchpattern and an execution program, the template.</p><p>To use XTP, you need an XTP file and an XSL stylesheet. XTP parsesthe XTP files as HTML and then evaluates the HTML using the stylesheet.Since XTP is a standard XSL processor, the following tutorials willapply to any other XSL engine. The main difference between XTP andan XSL engine like Xalan, is that XTP will automatically compilethe page to a JSP page. You can achieve the same effect with Xalan,but it takes a little more work.<p>The following example has a single template, matching any <hello>tag. When the XSL engine evaluates a <hello> tag it matches the rulein the stylesheet. In this case, it replaces the <hello> with"Hello, World". The <xsl:text> marks a text replacement.</p><example title='default.xsl'><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="hello"> <xsl:text>Hello, World</xsl:text></xsl:template></xsl:stylesheet></example><p>The following XTP file is first parsed as an HTML file and thenprocessed by the <var/default.xsl/> stylesheet. As mentioned above,the <hello/> tag is replaced by "Hello, World".</p><example title='hello.xtp'>My First Tag: <hello/></example><results>My First Tag: Hello, World</results><p>This above example hides a few details, namely the default XSL rules.XTP's parser automatically inserts the <html> and <body> elements,but as you see, they're not included in the result. If an XML node doesn'tmatch any stylesheet pattern, XSL applies a default rule. The default rulefor elements recursively evaluates the element children, but does not copythe element itself. Text nodes are copied. In the above example, thedefault rules eat the <html> and <body> elements, evaluating thechildren, but copy the "My First Tag: " text.</p><s2 title="StyleScript equivalent"><p>Resin provides an alternate syntax for XSL. XSL does not scan well; it'shard to find templates and figure out what they're doing. In other words, XSL can become a write-only language. StyleScript aims at having the samefunctionality of XSL, but making it more maintainable.</p><example title='default.xsl'>$template(hello) <<Hello, World>></example></s2><s2 title="Summary"><ul><li>XTP needs an XML file (the .xtp) and an XSL stylesheet.<li><var/default.xsl/> is the default stylesheet.<li><var/xsl:template/> matches an XML tag and replaces it with new XML.<li>The XPath pattern <var/name/> matches a named element.<li><var/<< ... >>/> describes the replacement XML in StyleScript.<li>XTP stylesheets provide syntactic sugar to XSL stylesheets, but arecompletely equivalent.<li><var/$template(foo)/> expands to <var/<xsl:template match="foo">/>.<li><var/xsl:text/> returns verbatim text.</ul></s2></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -