XSL Transform Prevented by a Declaration

A

Al Hatch

XSLT fails when the XML file contains this top-level declaration:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<P2Main xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:schemas-Professional-Plug-in:p2:ClipMetadata:v3.0">
<ClipName>0001FM</ClipName>
</P2Main>

However, XSLT succeeds when I modify the XML declaration to this:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<P2Main>
<ClipName>0001FM</ClipName>
</P2Main>

What is the declaration conflict here, and why would that simple deletion
make it work?


By the way, the XSL is

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:value-of select="P2Main/ClipName"/>
</xsl:template>
</xsl:stylesheet>
 
M

Martin Honnen

Al said:
XSLT fails when the XML file contains this top-level declaration:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<P2Main xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:schemas-Professional-Plug-in:p2:ClipMetadata:v3.0">
<ClipName>0001FM</ClipName>
</P2Main>

<xsl:stylesheet version="1.0"
Add
xmlns:cm="urn:schemas-Professional-Plug-in:p2:ClipMetadata:v3.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

and then use e.g.
<xsl:template match="/">
<xsl:value-of select="P2Main/ClipName"/>

<xsl:value-of select="cm:p2Main/pm:ClipName" />
 
A

Al Hatch

<xsl:value-of select="cm:p2Main/pm:ClipName" />

There was a typo in your repsonse (/pm should be /cm), but once I changed
that, it worked.

Apparently, namespace declarations in the XSL document must match the
namespace declarations in its source XML document, but I'm not clear on what
the cm namespace is. I guess I have to go back to the manual to find out
what's going on here.

Thanks.
 
M

Martin Honnen

Al Hatch wrote:

Apparently, namespace declarations in the XSL document must match the
namespace declarations in its source XML document, but I'm not clear on what
the cm namespace is. I guess I have to go back to the manual to find out
what's going on here.

The major problem is that while the XML document contains elements in a
default namespace (declared with xmlns="someURI") XPath needs a prefix
bound to the URL to match elements in the namespace.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top