简体   繁体   English

错误:尚未声明命名空间前缀“ og:image”:XSLT

[英]Error: Namespace prefix “og:image” has not been declared: XSLT

I am trying to convert an XML file into another XML file by using XSLT. 我正在尝试通过使用XSLT将XML文件转换为另一个XML文件。 This is the part of my XML(Input.xml) 这是我的XML(Input.xml)的一部分

    ...
<extension>
    <og:image>http://www.example.com/images/logos/logo-example-PNG.png</og:image>
    <og:type>article</og:type>
</extension>
    .......
...

This is the part of my XSLT which I am using on the tag og:image: 这是我在标签og:image上使用的XSLT的一部分:

....
<MT>
<xsl:attribute name="N">og:image</xsl:attribute>
<xsl:attribute name="V" select="/extension/og:image"/>
</MT>
...

I want my output to look like this (Output.xml) 我希望我的输出看起来像这样(Output.xml)

<MT N="og:image" V="http://www.example.com/images/logos/logo-example-PNG.png/>

But when I run my XSLT, I am getting this error. 但是,当我运行XSLT时,出现此错误。

XPST0081: Namespace prefix 'og' has not been declared

I might be missing something. 我可能会缺少一些东西。 I haven't worked with XSLT before with XML which has colon in between them. 在使用XSLT和XML之前,我还没有使用过XSLT。 Any help would be appreciated 任何帮助,将不胜感激

If you use a namespace prefix in a path expression or pattern like 如果您在路径表达式或模式中使用名称空间前缀,例如

select="/extension/og:image"

then you must declare the prefix in a namespace declaration on some containing element, for example 那么您必须在某些包含元素的名称空间声明中声明前缀,例如

<xsl:stylesheet ....
  xmlns:og="xxxxxxx"

where xxxxxxx matches the namespace URI used in the source document (which you haven't shown). 其中xxxxxxx与源文档中使用的名称空间URI匹配(未显示)。 Note that the source document and stylesheet can use different prefixes, the only thing that matters is that they are bound to the same namespace URI. 请注意,源文档和样式表可以使用不同的前缀,唯一重要的是它们被绑定到相同的名称空间URI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM