2011-01-23 72 views
4

當試圖從網頁閱讀我的xml我得到:「錯誤:在第8行,列23:綁定前綴」 下面是我的xml:問題解析與XSL XML在它

<?xml version="1.0"?> 
<outertag> 
<innertag sampleattribute="innertagAttribute"> 
    <Retailer> 
     RetailerName: 
     <xsl:template match="link"> 
      <a href="LinkGoesHere">Link</a> 
     </xsl:template> 
    </Retailer> 
</innertag> 

關於什麼是錯的任何想法?我的xml中不能使用xsl:template嗎?任何幫助是極大的讚賞。

+0

問得好,+1。請參閱我的回答以解釋問題以及一個簡單而簡短但完整的解決方案。 :) – 2011-01-23 07:09:01

+1

隨後的對話顯示,「unbound prefix」錯誤只是一個症狀;問題的根本原因是您還沒有理解XSLT與XML的關係。簡單的答案是,如果您要將XML發送到瀏覽器,則不:您不能簡單地在XML中包含XSLT指令並期望它們被執行。 – 2011-01-23 18:24:53

回答

4

When trying to read my xml from a webpage i get: "Error: At line 8, column 23: unbound prefix" Below is my xml:

<?xml version="1.0"?> 
<outertag> 
    <innertag sampleattribute="innertagAttribute"> 
     <Retailer>RetailerName: 
      <xsl:template match="link"> 
       <a href="LinkGoesHere">Link</a> 
      </xsl:template> 
     </Retailer> 
    </innertag> 
</outertag> 

Any ideas as to what is wrong? Can I not use xsl:template within my xml?

提供的文檔格式不正確和錯誤消息很好說的原因是什麼:

有一個名爲xsl:template的元素,但有是整個文檔結合中沒有命名空間聲明任何名稱空間的前綴xsl:

解決方案

正確非形成井文本的格式良好的XML文檔通過爲XSLT命名空間提供了一個命名空間聲明:

<outertag> 
    <innertag sampleattribute="innertagAttribute"> 
     <Retailer>RetailerName: 
      <xsl:template match="link" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
       <a href="LinkGoesHere">Link</a> 
      </xsl:template> 
     </Retailer> 
    </innertag> 
</outertag>