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

📄 jaxpxslt3.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 3 页
字号:
</h3><a name="wp64468"> </a><p class="pBody">This section ends with an overview of the XPath functions. You can use XPath functions to select a collection of nodes in the same way that you would use an an element specification like those you have already seen. Other functions return a string, a number, or a boolean value. For example, the expression <code class="cCode">/PROJECT/text()</code> gets the string-value of <code class="cCode">PROJECT</code> nodes. </p><a name="wp64469"> </a><p class="pBody">Many functions depend on the current context. In the example above, the <span style="font-style: italic">context</span> for each invocation of the <code class="cCode">text()</code> function is the <code class="cCode">PROJECT</code> node that is currently selected. </p><a name="wp64470"> </a><p class="pBody">There are many XPath functions--too many to describe in detail here. This section provides a quick listing that shows the available XPath functions, along with a summary of what they do. </p><hr><a name="wp64471"> </a><p class="pNote">Note: Skim the list of functions to get an idea of what's there. For more information, see Section 4 of the<a  href="http://www.w3.org/TR/xpath" target="_blank"> XPath Specification</a>.</p><hr><a name="wp64472"> </a><h4 class="pHeading3">Node-set functions</h4><a name="wp64473"> </a><p class="pBody">Many XPath expressions select a set of nodes. In essence, they return a <span style="font-style: italic">node-set</span>. One function does that, too.</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp64474"> </a><div class="pSmartList1"><li><code class="cCode">id(...)</code>--returns the node with the specified id.</li></div></ul></div><a name="wp64475"> </a><p class="pBody">(Elements only have an ID when the document has a DTD, which specifies which attribute has the <code class="cCode">ID</code> type.)</p><a name="wp64476"> </a><h4 class="pHeading3">Positional functions</h4><a name="wp64477"> </a><p class="pBody">These functions return positionally-based numeric values. </p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp64478"> </a><div class="pSmartList1"><li><code class="cCode">last()</code>--returns the index of the last element. </li></div><a name="wp76601"> </a><p class="pBodyRelative">For example: <code class="cCode">/HEAD[last()]</code> selects the last <code class="cCode">HEAD</code> element.</p><a name="wp64479"> </a><div class="pSmartList1"><li><code class="cCode">position()</code>--returns the index position. </li></div><a name="wp76605"> </a><p class="pBodyRelative">For example: <code class="cCode">/HEAD[position() &lt;= 5]</code> selects the first five <code class="cCode">HEAD</code> elements</p><a name="wp64480"> </a><div class="pSmartList1"><li><code class="cCode">count(...)</code>--returns the count of elements. </li></div><a name="wp76609"> </a><p class="pBodyRelative">For example: <code class="cCode">/HEAD[count(HEAD)=0]</code> selects all <code class="cCode">HEAD</code> elements that have no subheads.</p></ul></div><a name="wp64481"> </a><h4 class="pHeading3">String functions</h4><a name="wp64482"> </a><p class="pBody">These functions operate on or return strings.</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp64483"> </a><div class="pSmartList1"><li><code class="cCode">concat(</code><code class="cVariable">string</code><code class="cCode">, </code><code class="cVariable">string</code><code class="cCode">, ...)</code>--concatenates the string values</li></div><a name="wp64484"> </a><div class="pSmartList1"><li><code class="cCode">starts-with(</code><code class="cVariable">string1</code><code class="cCode">, </code><code class="cVariable">string2</code><code class="cCode">)</code>--returns true if <code class="cVariable">string1</code> starts with <code class="cVariable">string2</code></li></div><a name="wp64485"> </a><div class="pSmartList1"><li><code class="cCode">contains(</code><code class="cVariable">string1</code><code class="cCode">, </code><code class="cVariable">string2</code><code class="cCode">)</code>--returns true if <code class="cVariable">string1</code> contains <code class="cVariable">string2</code> </li></div><a name="wp64486"> </a><div class="pSmartList1"><li><code class="cCode">substring-before(</code><code class="cVariable">string1</code><code class="cCode">, </code><code class="cVariable">string2</code><code class="cCode">)</code>--returns the start of <code class="cVariable">string1</code> before <code class="cVariable">string2</code> occurs in it</li></div><a name="wp64487"> </a><div class="pSmartList1"><li><code class="cCode">substring-after(</code><code class="cVariable">string1</code><code class="cCode">, </code><code class="cVariable">string2</code><code class="cCode">)</code>--returns the remainder of <code class="cVariable">string1</code> after <code class="cVariable">string2</code> occurs in it</li></div><a name="wp64488"> </a><div class="pSmartList1"><li><code class="cCode">substring(</code><code class="cVariable">string</code><code class="cCode">, </code><code class="cVariable">idx</code><code class="cCode">)</code>--returns the substring from the index position to the end, where the index of the first char = 1</li></div><a name="wp64489"> </a><div class="pSmartList1"><li><code class="cCode">substring(</code><code class="cVariable">string</code><code class="cCode">, </code><code class="cVariable">idx</code><code class="cCode">, </code><code class="cVariable">len</code><code class="cCode">)</code>--returns the substring from the index position, of the specified length</li></div><a name="wp64490"> </a><div class="pSmartList1"><li><code class="cCode">string-length()</code>--returns the size of the context-node's string-value</li></div><a name="wp77077"> </a><p class="pBodyRelative">The <span style="font-style: italic">context node</span> is the currently selected node -- the node that was selected by an XPath expression in which a function like <code class="cCode">string-length()</code> is applied.</p><a name="wp64491"> </a><div class="pSmartList1"><li><code class="cCode">string-length(</code><code class="cVariable">string</code><code class="cCode">)</code>--returns the size of the specified string </li></div><a name="wp64492"> </a><div class="pSmartList1"><li><code class="cCode">normalize-space()</code>--returns the normalized string-value of the current node (no leading or trailing whitespace, and sequences of whitespace characters converted to a single space)</li></div><a name="wp64493"> </a><div class="pSmartList1"><li><code class="cCode">normalize-space(</code><code class="cVariable">string</code><code class="cCode">)</code>--returns the normalized string-value of the specified string</li></div><a name="wp64494"> </a><div class="pSmartList1"><li><code class="cCode">translate(</code><code class="cVariable">string1</code><code class="cCode">, </code><code class="cVariable">string2</code><code class="cCode">, </code><code class="cVariable">string3</code><code class="cCode">)</code>--converts <code class="cVariable">string1</code>, replacing occurrences of characters in <code class="cVariable">string2</code> with the corresponding character from <code class="cVariable">string3</code></li></div></ul></div><hr><a name="wp64495"> </a><p class="pNote">Note: XPath defines 3 ways to get the text of an element: <code class="cCode">text()</code>, <code class="cCode">string(object)</code>, and the string-value implied by an element name in an expression like this: <code class="cCode">/PROJECT[PERSON=&quot;Fred&quot;]</code>.</p><hr><a name="wp64496"> </a><h4 class="pHeading3">Boolean functions</h4><a name="wp64497"> </a><p class="pBody">These functions operate on or return boolean values:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp64498"> </a><div class="pSmartList1"><li><code class="cCode">not(...)</code>--negates the specified boolean value</li></div><a name="wp64499"> </a><div class="pSmartList1"><li><code class="cCode">true()</code>--returns true </li></div><a name="wp64500"> </a><div class="pSmartList1"><li><code class="cCode">false()</code>--returns false </li></div><a name="wp64501"> </a><div class="pSmartList1"><li><code class="cCode">lang(</code><code class="cVariable">string</code><code class="cCode">)</code>--returns true if the language of the context node (specified by <code class="cCode">xml:Lang</code> attributes) is the same as (or a sublanguage of) the specified language. For example: <code class="cCode">Lang(&quot;en&quot;)</code> is true for <code class="cCode">&lt;PARA_xml:Lang=&quot;en&quot;&gt;...&lt;/PARA&gt;</code> </li></div></ul></div><a name="wp64502"> </a><h4 class="pHeading3">Numeric functions</h4><a name="wp64503"> </a><p class="pBody">These functions operate on or return numeric values. </p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp64504"> </a><div class="pSmartList1"><li><code class="cCode">sum(...)</code>--returns the sum of the numeric value of each node in the specified node-set</li></div><a name="wp64505"> </a><div class="pSmartList1"><li><code class="cCode">floor(</code><code class="cVariable">N</code><code class="cCode">)</code>--returns the largest integer that is not greater than <code class="cVariable">N</code></li></div><a name="wp64506"> </a><div class="pSmartList1"><li><code class="cCode">ceiling(</code><code class="cVariable">N</code><code class="cCode">)</code>--returns the smallest integer that is greater than <code class="cVariable">N</code></li></div><a name="wp64507"> </a><div class="pSmartList1"><li><code class="cCode">round(</code><code class="cVariable">N</code><code class="cCode">)</code>--returns the integer that is closest to <code class="cVariable">N</code></li></div></ul></div><a name="wp64508"> </a><h4 class="pHeading3">Conversion functions</h4><a name="wp64509"> </a><p class="pBody">These functions convert one data type to another.</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp64510"> </a><div class="pSmartList1"><li><code class="cCode">string(...)</code>--returns the string value of a number, boolean, or node-set</li></div><a name="wp64511"> </a><div class="pSmartList1"><li><code class="cCode">boolean(...)</code>--returns a boolean value for a number, string, or node-set (a non-zero number, a non-empty node-set, and a non-empty string are all true)</li></div><a name="wp64513"> </a><div class="pSmartList1"><li><code class="cCode">number(...)</code>--returns the numeric value of a boolean, string, or node-set (true is 1, false is 0, a string containing a number becomes that number, the string-value of a node-set is converted to a number)</li></div></ul></div><a name="wp64515"> </a><h4 class="pHeading3">Namespace functions</h4><a name="wp64516"> </a><p class="pBody">These functions let you determine the namespace characteristics of a node. </p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp64517"> </a><div class="pSmartList1"><li><code class="cCode">local-name()</code>--returns the name of the current node, minus the namespace prefix</li></div><a name="wp64518"> </a><div class="pSmartList1"><li><code class="cCode">local-name(...)</code>--returns the name of the first node in the specified node set, minus the namespace prefix</li></div><a name="wp64519"> </a><div class="pSmartList1"><li><code class="cCode">namespace-uri()</code>--returns the namespace URI from the current node</li></div><a name="wp64520"> </a><div class="pSmartList1"><li><code class="cCode">namespace-uri(...)</code>--returns the namespace URI from the first node in the specified node set</li></div><a name="wp64521"> </a><div class="pSmartList1"><li><code class="cCode">name()</code>--returns the expanded name (URI plus local name) of the current node</li></div><a name="wp64522"> </a><div class="pSmartList1"><li><code class="cCode">name(...)</code>--returns the expanded name (URI plus local name) of the first node in the specified node set</li></div></ul></div><a name="wp64523"> </a><h3 class="pHeading2">Summary</h3><a name="wp64524"> </a><p class="pBody">XPath operators, functions, wildcards, and node-addressing mechanisms can be combined in wide variety of ways. The introduction you've had so far should give you a good head start at specifying the pattern you need for any particular purpose. </p>    </blockquote>   <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="JAXPXSLT2.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="JAXPXSLT4.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font>  </body></html>

⌨️ 快捷键说明

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