Prefix problem with XML/XSL

Discussion in 'XML' started by Jacques, Jun 23, 2004.

  1. Jacques

    Jacques Guest

    I'm experiencing the following problem

    The source xml file uses a prefix (wpl:) and look like this (shortened):
    -----------------------------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <wpl:Destinations xmlns:wpl="www.sapportals.com/portal/landscape"
    xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
    xsi:schemaLocation="wpl_jco_destionations_v10.xsd">

    <wpl:Destination name="SAP_R3_Financials_DEV200">
    <wpl:SYSTEM>ZSECDS1200</wpl:SYSTEM>
    <wpl:MSHOST>secacsap</wpl:MSHOST>
    <wpl:R3NAME>DS1</wpl:R3NAME>
    <wpl:CLIENT>200</wpl:CLIENT>
    </wpl:Destination>
    -----------------------------------------------------------------
    The xsl file i created loos like this:
    ----------------------------------------------------------------
    <?xml version="1.0" ?>
    <wpl:stylesheet xmlns:wpl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <wpl:eek:utput method="text"/>

    <wpl:template match="Destination">
    <wpl:value-of select="@name"/>
    </wpl:template>

    </wpl:stylesheet>
    -------------------------------------------------------------------

    I then run

    xalan -o output.txt jcoDestinations.xml jcoDestinations.xsl

    I would expect the output to be

    SAP_R3_Financials_DEV200

    however the output is:


    ZSECDS1200
    secacsap
    DS1
    200


    I removed all the "wpl:" from the source, changed the xls to use "xsl"
    rather than "wpl". This produces the expected output.

    Is this a bug, or am I doing somthing wrong?


    Regards
    Jacques
    Jacques, Jun 23, 2004
    #1
    1. Advertising

  2. Jacques wrote:
    > I'm experiencing the following problem
    >
    > The source xml file uses a prefix (wpl:) and look like this (shortened):
    > -----------------------------------------------------------------
    > <?xml version="1.0" encoding="UTF-8"?>
    > <wpl:Destinations xmlns:wpl="www.sapportals.com/portal/landscape"
    > xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
    > xsi:schemaLocation="wpl_jco_destionations_v10.xsd">
    >
    > <wpl:Destination name="SAP_R3_Financials_DEV200">
    > <wpl:SYSTEM>ZSECDS1200</wpl:SYSTEM>
    > <wpl:MSHOST>secacsap</wpl:MSHOST>
    > <wpl:R3NAME>DS1</wpl:R3NAME>
    > <wpl:CLIENT>200</wpl:CLIENT>
    > </wpl:Destination>
    > -----------------------------------------------------------------
    > The xsl file i created loos like this:


    maybe a tiny misunderstanding

    there's nothing wrong in your stylesheet (that is to say that it is a
    correct stylesheet, although it doesn't produce the expected result)

    however, your template doesn't handle elements from your xml source,
    because you have to define a xmlns declaration with a prefix bound to
    your data; as usually, the xslt namespace is bound to xsl, i recommend
    to use the prefix xsl for the xslt namespace, and wpl for your own datas :

    <?xml version="1.0" ?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wpl="www.sapportals.com/portal/landscape"
    version="1.0">

    <xls:eek:utput method="text"/>

    <xsl:template match="wpl:Destination">
    <xsl:value-of select="@name"/>
    </xsl:template>

    </xsl:stylesheet>

    you can see above that wpl:Destination matches the appropriate element
    because the prefix is bound to the same uri (using the same prefix is
    convenient but not mandatory)

    the xsl prefix is bound to the uri that correspond to xslt, and will be
    handled by your xslt processor

    notice that unprefixed attributes are never bound to a namespace uri, so
    one can safely use @name

    what counts : only the univeral name, that consists of the namespace uri
    and the local name (the name without the prefix); consider that a prefix
    is just an alias, that is neutral

    have a look at the namespace specification : a very little spec that
    have a huge major importance in xml technologies

    --
    Cordialement,

    ///
    (. .)
    -----ooO--(_)--Ooo-----
    | Philippe Poulard |
    -----------------------
    Philippe Poulard, Jun 23, 2004
    #2
    1. Advertising

  3. Jacques

    Rolf Magnus Guest

    Jacques wrote:

    > I'm experiencing the following problem
    >
    > The source xml file uses a prefix (wpl:) and look like this
    > (shortened):
    > -----------------------------------------------------------------
    > <?xml version="1.0" encoding="UTF-8"?> <wpl:Destinations
    > xmlns:wpl="www.sapportals.com/portal/landscape"
    > xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
    > xsi:schemaLocation="wpl_jco_destionations_v10.xsd">
    >
    > <wpl:Destination name="SAP_R3_Financials_DEV200">
    > <wpl:SYSTEM>ZSECDS1200</wpl:SYSTEM>
    > <wpl:MSHOST>secacsap</wpl:MSHOST>
    > <wpl:R3NAME>DS1</wpl:R3NAME>
    > <wpl:CLIENT>200</wpl:CLIENT>
    > </wpl:Destination>
    > -----------------------------------------------------------------
    > The xsl file i created loos like this:
    > ----------------------------------------------------------------
    > <?xml version="1.0" ?>
    > <wpl:stylesheet xmlns:wpl="http://www.w3.org/1999/XSL/Transform"
    > version="1.0">
    >
    > <wpl:eek:utput method="text"/>
    >
    > <wpl:template match="Destination">
    > <wpl:value-of select="@name"/>
    > </wpl:template>
    >
    > </wpl:stylesheet>
    > -------------------------------------------------------------------
    >
    > I then run
    >
    > xalan -o output.txt jcoDestinations.xml jcoDestinations.xsl
    >
    > I would expect the output to be
    >
    > SAP_R3_Financials_DEV200
    >
    > however the output is:
    >
    >
    > ZSECDS1200
    > secacsap
    > DS1
    > 200
    >
    >
    > I removed all the "wpl:" from the source, changed the xls to use "xsl"
    > rather than "wpl". This produces the expected output.
    >
    > Is this a bug, or am I doing somthing wrong?


    The prefix is not important for namespace resolution. The namespace uri
    is. In your xml file, all the elements are in the
    www.sapportals.com/portal/landscape namespace, which your style sheet
    doesn't know anything about.
    Rolf Magnus, Jun 23, 2004
    #3
  4. Jacques

    Jacques Guest

    Thank you for a very informative explanation, as well as a practical
    solution.
    It works now, and I understand why.

    Regards

    "Philippe Poulard" <> wrote in message
    news:cbbtej$c8n$...
    > Jacques wrote:
    > > I'm experiencing the following problem
    > >
    > > The source xml file uses a prefix (wpl:) and look like this (shortened):
    > > -----------------------------------------------------------------
    > > <?xml version="1.0" encoding="UTF-8"?>
    > > <wpl:Destinations xmlns:wpl="www.sapportals.com/portal/landscape"
    > > xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
    > > xsi:schemaLocation="wpl_jco_destionations_v10.xsd">
    > >
    > > <wpl:Destination name="SAP_R3_Financials_DEV200">
    > > <wpl:SYSTEM>ZSECDS1200</wpl:SYSTEM>
    > > <wpl:MSHOST>secacsap</wpl:MSHOST>
    > > <wpl:R3NAME>DS1</wpl:R3NAME>
    > > <wpl:CLIENT>200</wpl:CLIENT>
    > > </wpl:Destination>
    > > -----------------------------------------------------------------
    > > The xsl file i created loos like this:

    >
    > maybe a tiny misunderstanding
    >
    > there's nothing wrong in your stylesheet (that is to say that it is a
    > correct stylesheet, although it doesn't produce the expected result)
    >
    > however, your template doesn't handle elements from your xml source,
    > because you have to define a xmlns declaration with a prefix bound to
    > your data; as usually, the xslt namespace is bound to xsl, i recommend
    > to use the prefix xsl for the xslt namespace, and wpl for your own datas :
    >
    > <?xml version="1.0" ?>
    > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > xmlns:wpl="www.sapportals.com/portal/landscape"
    > version="1.0">
    >
    > <xls:eek:utput method="text"/>
    >
    > <xsl:template match="wpl:Destination">
    > <xsl:value-of select="@name"/>
    > </xsl:template>
    >
    > </xsl:stylesheet>
    >
    > you can see above that wpl:Destination matches the appropriate element
    > because the prefix is bound to the same uri (using the same prefix is
    > convenient but not mandatory)
    >
    > the xsl prefix is bound to the uri that correspond to xslt, and will be
    > handled by your xslt processor
    >
    > notice that unprefixed attributes are never bound to a namespace uri, so
    > one can safely use @name
    >
    > what counts : only the univeral name, that consists of the namespace uri
    > and the local name (the name without the prefix); consider that a prefix
    > is just an alias, that is neutral
    >
    > have a look at the namespace specification : a very little spec that
    > have a huge major importance in xml technologies
    >
    > --
    > Cordialement,
    >
    > ///
    > (. .)
    > -----ooO--(_)--Ooo-----
    > | Philippe Poulard |
    > -----------------------
    Jacques, Jun 23, 2004
    #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.
Similar Threads
  1. Tim Tyler
    Replies:
    36
    Views:
    1,460
    Darryl L. Pierce
    Dec 10, 2004
  2. Tjerk Wolterink

    XML: XSL: Unbounds Prefix

    Tjerk Wolterink, Nov 17, 2004, in forum: XML
    Replies:
    2
    Views:
    890
    Tjerk Wolterink
    Nov 17, 2004
  3. Replies:
    1
    Views:
    3,595
    A. Bolmarcich
    May 27, 2005
  4. Chris  Chiasson
    Replies:
    6
    Views:
    612
    Richard Tobin
    Nov 14, 2006
  5. Replies:
    5
    Views:
    1,216
Loading...

Share This Page