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

📄 xtp.xtp

📁 解压在c盘
💻 XTP
字号:
<s1 title="XTP (XML Template Pages)"><summarylist/><p>Serif (XML Template Pages) enhances JSP pages with stylesheets.Sophisticated projects can split page formatting from theJSP-generated content.  Splitting the graphic design from theJSP programming helps a web site in several ways:</p><ul><li>Stylesheets automatically reformat the entire site, so theweb site becomes more flexible.<li>Repetitive HTML formatting patterns are defined once, reducingformatting errors.<li>Multiple stylesheets can reformat the same content, displayingviews for browsers, handheld devices, and syndication.<li>XTP pages are compiled to JSP, so they have the same performanceas JSP.</ul><p>Since XTP is standards-based, developers benefit from widely-availablepublic documentation, tutorials and support.  Stylesheets are writtenin the W3C standard <a href="xsl.xtp">XSL</a> (XML StylesheetLanguage) and produce <a href="jsp.xtp">JSP</a> (Java Server Pages).</p><s2 name=blank title="Style Example"><p>The following shows a simple example of formatting JSP usingstylesheets.  The stylesheet formats a custom tag,<var/&lt;exclamation>/>.  The exclamation translatesinto the HTML <var/&lt;h1>/> and can be easily changedto any desired format.</p><p>Except for the formatting tags, the *.xtp file is a normal *.jspfile describing an HTML page.  Unlike JSP which copies its content asraw text, XTP parses the HTML contents into an internal tree (the XMLDOM).  A more aggressive *.xtp could use XML but most willuse XML only where useful.  Expressions, scriptlets, anddeclarations work just as JSP pages.</p><example title='hello.xtp'>&lt;?xml-stylesheet href="hello.xsl"?>&lt;head>&lt;title&gt;Hello, world&lt;/title&gt;&lt;% int count = 0; %>&lt;/head>&lt;exclamation&gt;Hi, World!&lt;/exclamation&gt;Count: &lt;%= count++ %></example><p>For everything but <var/exclamation/>, the stylesheet copies itsinput directly to the output.  Using this technique, you can add tagsas you develop them.  So a project can incrementally benefit fromXTP; you don't need to entirely redesign your site.</p><example title='hello.xsl'>&lt;xsl:output disable-output-escaping="true"/>&lt;!-- copy everything not matching to the output -->&lt;xsl:template match="*|@*">  &lt;xsl:copy>    &lt;xsl:apply-templates select="node()|@*"/>  &lt;/xsl:copy>&lt;/xsl:template>&lt;!-- format the exclamation -->&lt;xsl:template match="exclamation">  &lt;h1>    &lt;xsl:apply-templates select="node()|@*"/>  &lt;/h1>&lt;/xsl:template></example><p>The XTP engine produces a standard JSP file as anintermediate form.  The generated JSP will process the request.Since it's standard JSP, you can use any JSP or Servlet feature,including using custom JSP tags (although XSL tags are generallymore efficient.)</p><p>Unless the XTP source or the stylesheet changes, the XTP enginewill continue to use the compiled JSP page without additionalstylesheet processing.  So the XTP has the same performance of a JSPpage, with the flexibility of the stylesheet.</p><example title='_jsp/_hello.jsp'>&lt;html&gt;  &lt;head&gt;    &lt;title&gt;Hello, world&lt;/title&gt;    &lt;% int count; %>  &lt;/head&gt;  &lt;body&gt;    &lt;h1&gt;Hi, World!&lt;/h1&gt;    Count: &lt;%= count++ %>  &lt;/body&gt;&lt;/html&gt;</example></s2><s2 title="XTP Syntax"><p>By default, XTP pages are read in as HTML.  Non-HTML tags are treatedas XML, i.e. they're expected to have an end tag for every begin tag.By allowing HTML as a primary input format, XTP pages provide a smoothtransition path.  Sites don't need to transform every page to XML totake advantage of XTP's formatting.</p><p>Pages can also be written in strict XML.   If the page beginswith <var/&lt;?xml ... ?>/>, it will be read as strict XML.  New sitesmay choose to design using a strict XML base.</p></s2><s2 title="Stylesheets"><p>XTP Stylesheets can either use the <a href="xsl.xtp">XSL</a> or <ahref="stylescript.xtp">StyleScript</a> syntax.  Both have the samecapabilities.  StyleScript is more maintainable and readable, but XSLis a W3C standard.</p><s3 title="Selecting in the XTP file"><p>XTP pages generally select their stylesheet using the standard<var/xml-stylesheet/> processing instruction.  If no stylesheet isselected, the XTP page will use <var/default.xsl/>.</p><example>&lt;?xml version="1.0">&lt;?xml-stylesheet href="sample.xsl"?>&lt;top>  &lt;a/>  &lt;b/>&lt;/top></example></s3><s3 title="Stylesheet Search Path"><ol><li>The directory of the XTP file.<li>The application root.<li>WEB-INF/xsl.<li>The Java classpath.</ol><p>When building libraries of stylesheets, using the Java classpathhas several advantages.  It's naturally arranged in a path, it's familiar,and it is well supported by the servlet engines.</p></s3><s3 title="Dynamic Stylesheets"><p>The request parameter <var/caucho.xsl.stylesheet/> selects thestylesheet for the XTP page.  If set, it overrides the value specifiedin the XTP page.  A filter servlet can set <var/caucho.xsl.stylesheet/>to process the same page with different styles.  For example, a User-Agentfilter could select a different stylesheet for a Palm client or for aprintable version of the page.</p><example>public void service(HttpServletRequest req,                    HttpServletResponse res)  throws IOException, ServletException{  String style = req.getParameter("style");  if (style != null && style.equals("print"))    request.setAttribute("caucho.xsl.stylesheet", "print.xsl");  RequestDispatcher disp;  disp = getServletContext().getNamedDispatcher("xtp");  disp.forward(req, res);}</example></s3></s2><s2 title="Servlet Parameters"><p>The XTP engine can set <var/xsl:param/> variables taken from theservlet request.  Stylesheets can use these variables,like <var/xtp:path_info/>, to create several web pages out of a singlesource XTP.  A section, for example, might only be displayed if itmatches the <var/request.getPathInfo()/>.</p><p>Stylesheets must use <var/xsl:param/> to use servlet parameters.Unless the stylesheet declares its parameters, XTP will not pass thevalues to the stylesheet.</p><deftable><tr><th>xsl:param<th>Servlet Value<tr><td>xtp:context_path<td>request.getContextPath()<tr><td>xtp:servlet_path<td>request.getServletPath()<tr><td>xtp:path_info<td>request.getPathInfo()<tr><td><var/name/><td>request.getParameter("<var/name/>")</deftable><example>&lt;xsl:param name="xtp:path_info"/>&lt;!-- by default, section is not displayed -->&lt;xsl:template match="section"/>&lt;xsl:template match="section[$xtp:path_info=@name]">  &lt;h1>&lt;xsl:value-of select="@title">&lt;/h1>  &lt;xsl:apply-templates/>&lt;/xsl:template></example><p>A sample XTP file might look like:</p><example>&lt;body>&lt;section title="Introduction">This is the introduction.&lt;/section>&lt;section title="Conclusion">This is the conclusion.&lt;/section>&lt;/body></example></s2></s1>

⌨️ 快捷键说明

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