xsl schema and Namespaces issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • william_hulse@hotmail.com

    xsl schema and Namespaces issue

    The general process i am currently working on is this:


    STEP 1 xml doc1 is transformed using stylesheet1 to produce xml doc2

    - xml doc1 has a namespace declaration as follows...

    <?xml version="1.0" encoding="iso-8859-1" standalone="yes "?>
    <?xml-stylesheet type="text/xsl"
    href="G:\Workin g\User\Will_Hul se\NEW\xmldb\co de\Bank_Stateme nts_Schema\EXBA EUFRED01.xsl"?>
    <FILE>
    <GENERAL>
    ......

    </FILE>


    - stylesheet1 has namespace declaration as follows

    <?xml version="1.0"?>
    <xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output indent="yes"/>

    ....

    </xsl:stylesheet>

    - the result has namespace as follows


    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl"
    href="G:\Workin g\User\Will_Hul se\NEW\xmldb\co de\Bank_Stateme nts_Schema\EXBA EUFRED02.xsl"?>
    <FILE>
    <GENERAL>
    ....

    </file>

    .... which is fine

    STEP 2 - xml doc2 is transformed using stylesheet2 to produce xml doc3
    which must conform to an xml schema

    - xml doc2 has namespace as follows

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl"
    href="G:\Workin g\User\Will_Hul se\NEW\xmldb\co de\Bank_Stateme nts_Schema\EXBA EUFRED02.xsl"?>
    <FILE>
    <GENERAL>
    ....

    </file>


    - stylesheet2 has namespace declaration as follows

    ?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output method="xml" omit-xml-declaration="no " indent="yes"/>

    - but also has the following clause to insert namespace info into
    resulting document, 'linking' it to a schema bank_stat.xsd

    <FILE xmlns="http://www.oracle.com/bank_stat.xsd"
    xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocat ion="http://www.oracle.com/bank_stat.xsd
    G:\Working\User \Will_Hulse\NEW \xmldb\code\Ban k_Statements_Sc hema\BANK_STAT. xsd">
    <xsl:apply-templates select="BANK_ST ATEMENTS"/>
    </FILE>



    The result however contains the following with a bogus empty namespace
    declaration in BANK_STATEMENTS

    <?xml version="1.0" encoding="UTF-8"?>
    <FILE xmlns="http://www.oracle.com/bank_stat.xsd"
    xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocat ion="http://www.oracle.com/bank_stat.xsd
    G:\Working\User \Will_Hulse\NEW \xmldb\code\Ban k_Statements_Sc hema\BANK_STAT. xsd">
    <BANK_STATEMENT S xmlns="">
    <GENERAL>
    <FILENAME>EUBAE UFRED01.XML</FILENAME>
    .....



    -- the namespace of the schema is as follows

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.oracle.com/bank_stat.xsd"
    xmlns:xdb="http ://xmlns.oracle.co m/xdb"
    targetNamespace ="http://www.oracle.com/bank_stat.xsd"
    elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
    <xs:element name="FILE">
    <xs:complexType >



    Questions..

    - Why does the bank statements tag contain xmlns="" and how can we stop
    it happening?

    - Is there a better way to insert schema referencing into the result of
    an xsl transform?

    - How does the schema namespace attributes elementFormDefa ult and
    attributeFormDe fault play a part in this...
    making the value of elementFormDefa ult = "unqualifie d" in the schema
    makes the xml fail validation. If we
    then remove the bogus xmlns="" from the doc, it then passes
    validation..


    Any help with the above would be greatly appreciated...
    Regards

    Will

  • Stanimir Stamenkov

    #2
    Re: xsl schema and Namespaces issue

    /william_hulse@h otmail.com/:
    [color=blue]
    > - xml doc1 has a namespace declaration as follows...
    >
    > <?xml version="1.0" encoding="iso-8859-1" standalone="yes "?>
    > <?xml-stylesheet type="text/xsl"
    > href="G:\Workin g\User\Will_Hul se\NEW\xmldb\co de\Bank_Stateme nts_Schema\EXBA EUFRED01.xsl"?>
    > <FILE>
    > <GENERAL>
    > .....
    >
    > </FILE>[/color]

    Where's the namespace declaration?

    [...][color=blue]
    > - the result has namespace as follows
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <?xml-stylesheet type="text/xsl"
    > href="G:\Workin g\User\Will_Hul se\NEW\xmldb\co de\Bank_Stateme nts_Schema\EXBA EUFRED02.xsl"?>
    > <FILE>
    > <GENERAL>
    > ...
    >
    > </file>[/color]

    I don't see namespace declaration here, neither... plus the
    <FILE>...</file> is not well-formed.
    [color=blue]
    > - xml doc2 has namespace as follows
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <?xml-stylesheet type="text/xsl"
    > href="G:\Workin g\User\Will_Hul se\NEW\xmldb\co de\Bank_Stateme nts_Schema\EXBA EUFRED02.xsl"?>
    > <FILE>
    > <GENERAL>
    > ...
    >
    > </file>[/color]

    Man, where do you see those namespace declarations!?
    [color=blue]
    > - stylesheet2 has namespace declaration as follows
    >
    > ?xml version="1.0" encoding="ISO-8859-1"?>
    > <xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    > version="1.0">
    > <xsl:output method="xml" omit-xml-declaration="no " indent="yes"/>
    >
    > - but also has the following clause to insert namespace info into
    > resulting document, 'linking' it to a schema bank_stat.xsd[/color]

    Where's the "clause" to insert that (following) namespace info?
    [color=blue]
    > <FILE xmlns="http://www.oracle.com/bank_stat.xsd"
    > xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    > xsi:schemaLocat ion="http://www.oracle.com/bank_stat.xsd
    > G:\Working\User \Will_Hulse\NEW \xmldb\code\Ban k_Statements_Sc hema\BANK_STAT. xsd">
    > <xsl:apply-templates select="BANK_ST ATEMENTS"/>
    > </FILE>
    >
    > The result however contains the following with a bogus empty namespace
    > declaration in BANK_STATEMENTS
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <FILE xmlns="http://www.oracle.com/bank_stat.xsd"
    > xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    > xsi:schemaLocat ion="http://www.oracle.com/bank_stat.xsd
    > G:\Working\User \Will_Hulse\NEW \xmldb\code\Ban k_Statements_Sc hema\BANK_STAT. xsd">
    > <BANK_STATEMENT S xmlns="">
    > <GENERAL>
    > <FILENAME>EUBAE UFRED01.XML</FILENAME>
    > ....[/color]
    [...][color=blue]
    > Questions..
    >
    > - Why does the bank statements tag contain xmlns="" and how can we stop
    > it happening?[/color]

    I didn't see any default namespace declarations in your stylesheets
    (or in what you've shown), but then it shouldn't need to output a
    default nonamespace declaration if it is the root of your document,
    I think.
    [color=blue]
    > - Is there a better way to insert schema referencing into the result of
    > an xsl transform?[/color]

    You didn't show how do you do it, currently.
    [color=blue]
    > - How does the schema namespace attributes elementFormDefa ult and
    > attributeFormDe fault play a part in this...
    > making the value of elementFormDefa ult = "unqualifie d" in the schema
    > makes the xml fail validation. If we
    > then remove the bogus xmlns="" from the doc, it then passes
    > validation..[/color]

    Too many questions - define more precise issues/topics and post
    questions separately. Post or preferably point URLs to complete
    examples you're trying with and which demonstrate your problem.

    --
    Stanimir

    Comment

    • will

      #3
      Re: xsl schema and Namespaces issue

      Apologies for some of this i was in a rush to get out of the office...

      Anyway some additional info..

      We can ignore STEP 1 as it works fine

      STEP 2 The xml is then transformed using a second xsl to produce a
      final xml
      which must conform to an xml schema

      - xml has no explicit namespace declaration as follows..

      <?xml version="1.0" encoding="UTF-8"?>
      <?xml-stylesheet type="text/xsl"
      href="G:\Workin g\User\Will_Hul se\NEW\xmldb\co de\Bank_Stateme ­nts_Schema\EXB AEUFRED02.xsl"? >

      <FILE>
      <GENERAL>
      ....
      </FILE>

      - stylesheet2 has again standard xsl namespace declaration as follows

      ?xml version="1.0" encoding="ISO-8859-1"?>
      <xsl:styleshe et
      xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"versi on="1.0">
      <xsl:output method="xml" omit-xml-declaration="no " indent="y­es"/>

      - but also contains the following fragment to create a FILE element
      that includes namespace info, 'linking' it to a schema bank_stat.xsd

      <FILE xmlns="http://www.oracle.com/bank_stat.xsd"
      xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"xsi:sc hemaLocation="h ttp://www.oracle.com/bank_stat.xsd

      G:\Working\User \Will_Hulse\NEW \xmldb\code\Ban k_Statements_Sc ­hema\BANK_STAT .xsd">

      <xsl:apply-templates select="BANK_ST ATEMENTS"/>
      </FILE>

      - The result from the above transformation however contains the
      following fragment with a bogus empty namespace declaration ie
      <BANK_STATEMENT S xmlns="">

      <?xml version="1.0" encoding="UTF-8"?>
      <FILE xmlns="http://www.oracle.com/bank_stat.xsd"
      xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"xsi:sc hemaLocation="h ttp://www.oracle.com/bank_stat.xsd

      G:\Working\User \Will_Hulse\NEW \xmldb\code\Ban k_Statements_Sc ­hema\BANK_STAT .xsd">

      <BANK_STATEMENT S xmlns="">
      <GENERAL>
      <FILENAME>EUBAE UFRED01.XML</FILENAME>
      .....

      - the namespace declaration of the schema the above xml has to conform
      to is as follows:

      <?xml version="1.0" encoding="UTF-8"?>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns="http://www.oracle.com/bank_stat.xsd"
      xmlns:xdb="http ://xmlns.oracle.co m/xdb"targetNames pace="http://www.oracle.com/bank_stat.xsd"

      elementFormDefa ult="qualified" attributeFormDe fault="unquali­ fied">
      <xs:element name="FILE">
      <xs:complexType >

      Questions..


      1 - Why does the bank statements tag contain xmlns="" and how can we
      stop it happening?
      2 - Is there a better way to insert schema referencing into the result
      of an xsl transform?
      3 - How does the schema namespace attributes elementFormDefa ult and
      attributeFormDe fault play a part in this...
      making the value of elementFormDefa ult = "unqualifie d" in the schema
      makes the xml fail validation. If we
      then remove the bogus xmlns="" from the doc, it then passes
      validation..


      Any help with the above would be greatly appreciated...
      Regards

      Will

      Comment

      • Stanimir Stamenkov

        #4
        Re: xsl schema and Namespaces issue

        /will/:
        [color=blue]
        > - but also contains the following fragment to create a FILE element
        > that includes namespace info, 'linking' it to a schema bank_stat.xsd
        >
        > <FILE xmlns="http://www.oracle.com/bank_stat.xsd"
        > xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"xsi:sc hemaLocation="h ttp://www.oracle.com/bank_stat.xsd
        >
        > G:\Working\User \Will_Hulse\NEW \xmldb\code\Ban k_Statements_Sc ­hema\BANK_STAT .xsd">
        >
        > <xsl:apply-templates select="BANK_ST ATEMENTS"/>
        > </FILE>
        >
        > - The result from the above transformation however contains the
        > following fragment with a bogus empty namespace declaration ie
        > <BANK_STATEMENT S xmlns="">[/color]

        Again, it is hard to guess from the partial messy sources you're
        posting - next time just put complete examples (which need not to be
        the originals if they contain sensitive information), which
        demonstrate your problem, on the web and point to them. Either way
        you're throwing away your chances somebody would have a look at your
        problem.

        Anyway, probably the "BANK_STATEMENT S" element is not descendant of
        the "FILE" element (where you declare the default namespace) in the
        stylesheet, so it effectively doesn't have a namespace - that's why
        the generated xmlns="" appears (because in the generated structure
        the "BANK_STATEMENT S" is descendant of the "FILE"). You should
        declare the default namespace at the root stylesheet element:

        <xsl:styleshe et version="1.0"
        xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
        xmlns="http://www.oracle.com/bank_stat.xsd">
        ...
        </xsl:stylesheet>

        --
        Stanimir

        Comment

        Working...