starts-with 函式
若第一個引數字串以第二個引數字串開頭則會傳回 True,否則傳回 False。
boolean starts-with(string, string)
備註
如果引數的型別不是 string,則會先使用 string() 函式將它轉換成字串,然後再評估該轉換的結果。
注意
當作引數傳遞至此函式的節點集字串轉換,有可能會產生非預期的結果。如需詳細資訊,請參閱 string 函式。
此函式有區分大小寫。
範例
下列範例將說明如何使用 starts-with() 函式來查詢標題以大寫字母 "W" 開頭的書籍集合。
XML 檔 (starts-with.xml)
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl"
href="contains.xsl"?>
<bookstore>
<book>
<title>The Weather Pattern</title>
<author>Weather Man</author>
<price>100.00</price>
</book>
<book>
<title>Weaving Patterns</title>
<author>Weaver</author>
<price>150.00</price>
</book>
<book>
<title>Speech Pattern</title>
<author>Speaker</author>
<price>15.00</price>
</book>
<book>
<title>Writing Style</title>
<author>Writer</author>
<price>1500.00</price>
</book>
</bookstore>
XSLT 檔 (starts-with.xsl)
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"
omit-xml-declaration="yes"/>
<xsl:template match="/">
<html>
<head><title>example</title></head>
<body>
<xsl:apply-templates select="//book"/>
</body>
</html>
</xsl:template>
<xsl:template match="book">
<xsl:if test="starts-with(title, 'W')">
<DIV>
<B><xsl:value-of select="title"/></B> by
<I><xsl:value-of select="author"/></I> costs
<xsl:value-of select="price"/>.
</DIV>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
輸出
此 XSLT 樣式表在套用至 XML 檔 (starts-with.xml) 時,則會產生下列輸出:
Weaving Patterns by Weaver costs 150.00.
Writing Style by Writer costs 1500.00.