ms:namespace-uri 函式
將限定名稱的前置詞部分解析到命名空間 URI。
string ms:namespace-uri(string)
備註
ms:namespace-uri() 函式假設參數是限定名稱 (例如,q:mine 或 coffee:beans),並且會嘗試解析目前節點之內容的前置詞。 若引數並非限定名稱或不含冒號的名稱,此函式就會傳回空字串。 對於非字串引數,此函式的行為會和套用 string() 函式時相同。
範例
下列範例將使用 XSLT 範本規則來選取 books.xml 中的所有項目,以及輸出項目的資料型別與命名空間 URI,如 books.xsd 中所定義。
XML 檔 (books.xml)
使用使用 XPath 擴充程式函式以獲得 XSD 支援中的 XML 檔案。
XSD 檔 (books.xsd)
使用使用 XPath 擴充程式函式以獲得 XSD 支援中的 XSD 檔案。
HTML 檔 (books.html)
HTML 檔與 ms:type-namespace-uri([node-set]) 函式主題中所列的檔案相同。
XSLT 檔 (books.xsl)
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="text()"/>
<xsl:output method="html"
omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*">
<xsl:if test="ms:type-namespace-uri() != ''">
<DIV>
(ms:)
<xsl:value-of select="ms:namespace-uri(name())"/>:
<xsl:value-of select="ms:local-name(name())"/>
</DIV>
<DIV>
(std:)
<xsl:value-of select="namespace-uri()"/>:
<xsl:value-of select="local-name()"/>
</DIV>
<DIV>
(name():)
<xsl:value-of select="name()"/>
</DIV>
</xsl:if>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
輸出
(ms:) urn:books:catalog
(std:) urn:books:catalog
(name():) x:catalog
輸出的第一行是由 ms:namespace-uri(string) 加上 ms:local-name(string) 傳回的結果。 第二行是標準 XPath 函式 namespace-uri(nodeset)、local-name(nodeset 傳回的結果。 第三行是標準 XPath 函式 name(nodeset) 傳回的結果。