value-of.xtp
来自「resinweb服务器源文件」· XTP 代码 · 共 65 行
XTP
65 行
<s1 title="XSL value-of"><p>Often, stylesheets need to grab data from the XML file and rearrangethem in the template results. The previous examples used template matchingfor all processing, but couldn't grab data within the template pattern.<var/xsl:value-of/> is the main XSL element to grab data from the XML.<p><var/xsl:value-of/> extracts data with an XPath<var/select/> expression. <var/select/> and the template's <var/match/>pattern use the same syntax, but are used differently. For a matchpattern, XSL has a current node and chooses the best matching pattern andits template. With a select pattern, XSL starts from a node and selectsstrings, numbers, or nodes from that node.<p>The following example uses xsl:value-of to extract the <var/@name/>attribute to customize the message. The xsl:value-of adds textto the output.</p><example title='default.xsl'><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="hello"> <xsl:text>Hello, </xsl:text> <xsl:value-of select="@name"/></xsl:template></xsl:stylesheet></example><p>As the following XTP file shows, using xsl:value-of with XMLattributes gives more power to the custom tags.</p><example title='hello.xtp'>Tag attributes: <hello name="Dolly"/></example><results>Tag attributes: Hello, Dolly</results><s2 title="StyleScript"><p>Because xsl:value-of is so common, StyleScript has a special syntaxfor it. $(<var/select/>) will write the text value of the selectpattern to the output.</p><example title='default.xsl'>$template(hello) <<Hello, $(@text)>></example></s2><s2 title="Summary"><ul><li>The XPath pattern <var/@attr/> matches tag attributes.<li><var/xsl:value-of/> extracts values from the XML.<li><var/<< ... >>/> trims initial and final linefeeds.<li><var/$(...)/> expands to <var/<xsl:value-of select="..."/>/></ul></s2></s1>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?