XSL Transform Prevented by a Declaration

Discussion in 'XML' started by Al Hatch, Jun 4, 2006.

  1. Al Hatch

    Al Hatch Guest

    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>
     
    Al Hatch, Jun 4, 2006
    #1
    1. Advertising

  2. Al Hatch wrote:

    > 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" />


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 4, 2006
    #2
    1. Advertising

  3. Al Hatch

    Al Hatch Guest

    On Sun, 4 Jun 2006 07:54:47 -0700, Martin Honnen wrote
    (in article <4482f43b$0$4498$-online.net>):

    > <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.
     
    Al Hatch, Jun 4, 2006
    #3
  4. 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.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 4, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page