- XPath 教程
- XPath - 主頁
- XPath - 概述
- XPath - 表示式
- XPath - 節點
- XPath - 絕對路徑
- XPath - 相對路徑
- XPath - 軸
- XPath - 運算子
- XPath - 萬用字元
- XPath - 謂詞
- XPath 有用資源
- XPath - 快速指南
- XPath - 有用資源
- XPath - 討論
XPath - 字串函式
以下是 XPath 字串函式列表 -
| 序號 | 函式和描述 |
|---|---|
| 1 | starts-with(string1, string2) 當第一個字串以第二個字串開頭時返回 true。 |
| 2 | contains(string1, string2) 當第一個字串包含第二個字串時返回 true。 |
| 3 | substring(string, offset, length?) 返回字串的部分內容。該部分從偏移量開始,直到提供的長度為止。 |
| 4 | substring-before(string1, string2) 返回 string1 中在 string2 第一次出現之前的所有部分。 |
| 5 | substring-after(string1, string2) 返回 string1 中在 string2 第一次出現之後的部分。 |
| 6 | string-length(string) 以字元為單位返回字串的長度。 |
| 7 | normalize-space(string) 修剪字串中的前導和尾隨空格。 |
| 8 | translate(string1, string2, string3) 在 string2 中的任何匹配字元被 string3 中的字元替換後,返回 string1。 |
| 9 | concat(string1, string2, ...) 連線所有字串。 |
| 10 | format-number(number1, string1, string2) 在將 string1 應用為格式字串後,返回 number1 的格式化版本。string2 是一個可選的區域字串。 |
示例
此示例透過遍歷每個學生,建立一個包含
students.xml
<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "students.xsl"?>
<class>
<student rollno = "393">
<firstname>Dinkar</firstname>
<lastname>Kad</lastname>
<nickname>Dinkar</nickname>
<marks>85</marks>
</student>
<student rollno = "493">
<firstname>Vaneet</firstname>
<lastname>Gupta</lastname>
<nickname>Vinni</nickname>
<marks>95</marks>
</student>
<student rollno = "593">
<firstname>Jasvir</firstname>
<lastname>Singh</lastname>
<nickname>Jazz</nickname>
<marks>90</marks>
</student>
</class>
students.xsl
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h2>Students</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Name</th>
<th>Length of Name</th>
</tr>
<xsl:for-each select = "class/student">
<tr>
<td><xsl:value-of select = "concat(firstname,' ',lastname)"/></td>
<td><xsl:value-of select = "string-length(concat(firstname,' ',lastname))"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
驗證輸出
xpath_operators.htm
廣告