XSL namespace problem

Discussion in 'XML' started by Sandy, Dec 15, 2005.

  1. Sandy

    Sandy Guest

    Hi,
    I have the follwing XML and XSL files, i want to do XSL transformation but
    its not working because of the presence of xmlns="Science" in the Envelope
    element, It works fine after removing it.

    I want to know how do i specify this namespace in XSL.

    file.xml
    <?xmlversion ="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xml" href="file.xsl"?>
    <Envelope
    xmlns="Science"><Header><class>A</class><activityName>Run</activityName><msg
    Name></Header></Envelope>


    file.xsl
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="Science">
    <xsl:template match="Envelope"><xsl:apply-templates/></xsl:template>
    <xsl:template match="Header"><xsl:value-of select="class"/></xsl:template>
    </xsl:stylesheet>

    Thanks
     
    Sandy, Dec 15, 2005
    #1
    1. Advertising

  2. Sandy wrote:
    > Hi,
    > I have the follwing XML and XSL files, i want to do XSL transformation but
    > its not working because of the presence of xmlns="Science" in the Envelope
    > element, It works fine after removing it.


    in XML, non-prefixed names are endorsing the default namespace, which is
    "Science" in your case
    namespaces are working like families :
    -<Envelope> is the firstname
    -"Science" is the familyname

    in XPath, non-prefixed names have no namespace
    thus, in XSLT, as match="Envelope" is used without namespaces, it means
    that you refer to :
    -<Envelope> as the firstname
    -no familyname

    which is not the element that you have in your source document

    in your XSLT document, you must deal with the XPath requirements :

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="Science">
    ^^^^^^^^^

    <xsl:template match="foo:Envelope"><xsl:apply-templates/></xsl:template>
    <xsl:template match="foo:Header"><xsl:value-of
    select="foo:class"/></xsl:template>
    </xsl:stylesheet>

    -----------------------

    notice that xmlns declarations should be non-relative URIs
    URIs are just universal identifiers, that enforce familynames to be unique

    xmlns="Science" is totally useless, because it might be not unique
    xmlns="http://yourcompany.com/Science" is universally unique and ensures
    that a name defined with :
    -<Envelope>
    -"http://yourcompany.com/Science"
    can't be ambiguous

    >
    > I want to know how do i specify this namespace in XSL.
    >
    > file.xml
    > <?xmlversion ="1.0" encoding="UTF-8"?>
    > <?xml-stylesheet type="text/xml" href="file.xsl"?>
    > <Envelope
    > xmlns="Science"><Header><class>A</class><activityName>Run</activityName><msg
    > Name></Header></Envelope>
    >
    >
    > file.xsl
    > <?xml version="1.0"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="Science">
    > <xsl:template match="Envelope"><xsl:apply-templates/></xsl:template>
    > <xsl:template match="Header"><xsl:value-of select="class"/></xsl:template>
    > </xsl:stylesheet>
    >
    > Thanks
    >
    >



    --
    Cordialement,

    ///
    (. .)
    -----ooO--(_)--Ooo-----
    | Philippe Poulard |
    -----------------------
     
    Philippe Poulard, Dec 15, 2005
    #2
    1. Advertising

  3. Sandy

    JAPISoft Guest

    Try something like that :

    <xsl:stylesheet version="1.0"
    xmlns:xsl="..." xmlns:env="Science">
    <xsl:template match="env:Envelope"><xsl:apply-templates/></xsl:template>
    <xsl:template match="env:Header"><xsl:value-of
    select="class"/></xsl:template>
    </xsl:stylesheet>

    Best regards,

    A.Brillant
    EditiX - XML Editor and XSLT Debugger
    http://www.editix.com


    Sandy wrote:
    > Hi,
    > I have the follwing XML and XSL files, i want to do XSL transformation but
    > its not working because of the presence of xmlns="Science" in the Envelope
    > element, It works fine after removing it.
    >
    > I want to know how do i specify this namespace in XSL.
    >
    > file.xml
    > <?xmlversion ="1.0" encoding="UTF-8"?>
    > <?xml-stylesheet type="text/xml" href="file.xsl"?>
    > <Envelope
    > xmlns="Science"><Header><class>A</class><activityName>Run</activityName><msg
    > Name></Header></Envelope>
    >
    >
    > file.xsl
    > <?xml version="1.0"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="Science">
    > <xsl:template match="Envelope"><xsl:apply-templates/></xsl:template>
    > <xsl:template match="Header"><xsl:value-of select="class"/></xsl:template>
    > </xsl:stylesheet>
    >
    > Thanks
    >
    >
     
    JAPISoft, Dec 15, 2005
    #3
  4. Sandy wrote:


    > <?xml-stylesheet type="text/xml" href="file.xsl"?>
    > <Envelope
    > xmlns="Science"><Header><class>A</class><activityName>Run</activityName><msg
    > Name></Header></Envelope>


    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="Science">


    Use
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:sc="Science"
    and then

    > <xsl:template match="Envelope"><xsl:apply-templates/></xsl:template>


    <xsl:template match="sc:Envelope">

    > <xsl:template match="Header"><xsl:value-of select="class"/></xsl:template>


    <xsl:template match="sc:Header"><xsl:value-of select="sc:class" />

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 15, 2005
    #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. Èý¹â
    Replies:
    1
    Views:
    585
    William F. Robertson, Jr.
    Jul 29, 2003
  2. Replies:
    0
    Views:
    5,146
  3. Lothar Lemnitzer
    Replies:
    1
    Views:
    514
    Richard Tobin
    Sep 21, 2004
  4. Replies:
    1
    Views:
    3,637
    A. Bolmarcich
    May 27, 2005
  5. Anonymous
    Replies:
    3
    Views:
    542
    Ron Natalie
    Aug 18, 2003
Loading...

Share This Page