2012-05-31 150 views
1

來源:Accesing節點的命名空間,XSLT

<Data> 
    <heading xmlns="Some Uri"> 
       <text>aaa</text> 


    </heading> 
    <Data> 

XSLT寫道

  <?xml version="1.0" encoding="utf-8"?> 
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:link1="Some Uri"> 
       <xsl:output method="xml" indent="yes"/> 

        <xsl:template match="Data"> 
        <xsl:value-of select="link1:heading/namespace-uri()"/> 

        </xsl:template> 


      </xsl:stylesheet> 

我得到的錯誤。

任何人都可以幫助如何獲得命名空間。

謝謝。

+0

我相信你正在尋找'namespace-uri()' http://stackoverflow.com/questions/529556/xpath-find-elements-by-attribute-namespace – StuartLC

+0

您輸入的XML不是值(額外的'')。 – Phrogz

回答

1

nonnb應作出評論的答案...

的命名空間URI()函數,你想要做什麼。

+0

我嘗試過,我收到錯誤。我用我所做的事情編輯了這個問題。 – Patan

+0

我編輯了這個問題,我無法獲得節點的名稱空間。你能幫我怎麼做 – Patan

1
<xsl:value-of select="link1:heading/namespace-uri()"/> 

在XSLT 1.0/1.0的XPath這是一個語法錯誤

正確這

<xsl:value-of select="namespace-uri(link1:heading)"/> 

在XSLT 2.0/XPath 2.0中這又是一個錯誤(namespace-uri()的說法不能ommitted正確的:

<xsl:value-of select="link1:heading/namespace-uri(.)"/> 
+0

我認爲select =「link1:heading/namespace-uri()」應該在XSLT 2.0中工作。 –

+0

@MichaelKay:也許你是對的 - 我發現很難和沒有必要記住哪些函數可以省略它們的參數,哪些不是 - 所以總是提供參數更安全。 –