用XSL解析XML的问题

时间:2011-01-23 06:56:20

标签: android xml xslt xml-parsing

当我尝试从网页上读取我的xml时,我得到:“错误:在第8行,第23行:未绑定的前缀” 下面是我的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吗?非常感谢任何帮助。

1 个答案:

答案 0 :(得分:4)

  

尝试从中读取我的xml时   网页我得到:“错误:在第8行,   第23列:未绑定的前缀“下面是我的   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>
     

关于什么是错的任何想法?我可以吗   我的xml中不使用xsl:template?

提供的文档格式不正确,错误信息说明原因是什么:

有一个名为xsl:template的元素,但整个文档中没有名称空间声明将前缀xsl:绑定到任何名称空间。

<强>解决方案

通过为XSLT名称空间提供名称空间声明,将非格式良好的文本更正为格式良好的XML文档:

<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>
相关问题