1
votes

I am trying to convert an XML file into another XML file by using XSLT. This is the part of my 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:

....
<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)

<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.

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. Any help would be appreciated

1

1 Answers

2
votes

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). 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.