xsl-filter.xtp

来自「解压在c盘」· XTP 代码 · 共 74 行

XTP
74
字号
<s1 title="XSL Filter"><p>XSL, the XML stylesheet language, simplifies creating a uniformstyle for a site.  XSL converts XML to HTML or XML or WAP.It's easy to create different output depending on the browser.  Justchoose another stylesheet.  The example below creates HTML or XMLresults from the same JSP.</p><p>The JSP page creates a simple XML file.  It tells Resin to use XSLfiltering by setting the contentType to<var>x-application/xslt</var>.  In this case, we're selecting thexml.xsl stylesheet.</p><example title='test.jsp'>&lt;%@ page session=false contentType='x-application/xslt' %>&lt;?xml-stylesheet href='xml.xsl'?>&lt;top>  &lt;title>Hello, world&lt;/title>  &lt;count>&lt;%= 1 + 1 %>&lt;/count>&lt;/top></example><p>Stylesheets belong in <var>WEB-INF/xsl</var>.  If nostylesheet is selected, Resin will use <var>default.xsl</var>.</p><p>The xml.xsl stylesheet just copies the input to the output.  Manystylesheets will use this rule as a default rule.</p><example title='xml.xsl'>&lt;xsl:stylesheet>&lt;xsl:template match='*|@*'>&lt;xsl:copy>&lt;xsl:apply-templates select='node()|@*'/>&lt;/xsl:copy>&lt;/xsl:template>&lt;/xsl:stylesheet></example><s2 title='HTML generation'><p>The HTML example is slightly more complicated.  When it matches a<var>top</var>, it generates the HTML header information.  The<var>count</var> tag just writes out the count.</p><example title='html.xsl'>&lt;xsl:stylesheet>&lt;xsl:output media-type='text/html'/>&lt;xsl:template match='top'>&lt;html>&lt;head>&lt;title>&lt;xsl:value-of select='title'/>&lt;/title>&lt;/head>&lt;body bgcolor='white'>&lt;h3>&lt;xsl:value-of select='title'/>&lt;/h3>&lt;xsl:apply-templates/>&lt;/body>&lt;/html>&lt;/xsl:template>&lt;xsl:template match='count'>Count: &lt;xsl:apply-templates/>&lt;br/>&lt;/xsl:template>&lt;xsl:template match='title'/>&lt;/xsl:stylesheet></example></s2></s1>

⌨️ 快捷键说明

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