Copying without namespace?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andre-John Mas

    Copying without namespace?

    Hi,

    I have some code that looks as follows:

    <xsl:for-each select="$pageMe taData/*">
    <xsl:choose>
    <xsl:when test="local-name() = 'meta'">
    <xsl:copy-of select="."/>
    </xsl:when>
    <xsl:otherwis e>
    <meta content="{.}" name="{local-name()}"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:for-each>

    The problem is that it copies the namespace when it does so (it
    appears to be implied, rather than declared). So this:

    <meta content="abc" name="dc.creato r"/>

    becomes this in the final output:

    <meta xmlns="http://www.myco.com/datalist" content="yuri"
    name="dc.creato r"/>

    How do I copy the element and not have the namespace in the result?
    Note that I only want to apply this here, and not globaly to all
    cases.

    Andre
  • Pavel Lepin

    #2
    Re: Copying without namespace?


    Andre-John Mas <andrejohn.mas@ gmail.comwrote in
    <4d1e8b09-6641-497e-a194-f87f9b905c8e@s1 2g2000prg.googl egroups.com>:
    <xsl:for-each select="$pageMe taData/*">
    <xsl:choose>
    <xsl:when test="local-name() = 'meta'">
    <xsl:copy-of select="."/>
    </xsl:when>
    <xsl:otherwis e>
    <meta content="{.}" name="{local-name()}"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:for-each>
    Awful.
    The problem is that it copies the namespace when it does
    so (it appears to be implied, rather than declared).
    "Implied rather than declared"? What do you mean?
    So this:
    >
    <meta content="abc" name="dc.creato r"/>
    >
    becomes this in the final output:
    >
    <meta xmlns="http://www.myco.com/datalist" content="yuri"
    name="dc.creato r"/>
    And what is the problem - the fact that your resulting meta
    element is in http://www.myco.com/datalist namespace, or
    the fact that this namespace is explicitly declared as the
    default namespace on this element?
    How do I copy the element and not have the namespace in
    the result?
    You can't. You can only create an element with the same
    name, but not in a namespace.

    I would recommend posting a minimal complete example of your
    problem, since it's not really clear to me what your
    problem is. Reading some introductory materials on XML
    Namespaces might be advisable as well.

    --
    When all you have is a transformation engine, everything
    looks like a tree.

    Comment

    • Johannes Koch

      #3
      Re: Copying without namespace?

      Pavel Lepin schrieb:
      Andre-John Mas <andrejohn.mas@ gmail.comwrote in
      <4d1e8b09-6641-497e-a194-f87f9b905c8e@s1 2g2000prg.googl egroups.com>:
      > <xsl:for-each select="$pageMe taData/*">
      > <xsl:choose>
      > <xsl:when test="local-name() = 'meta'">
      > <xsl:copy-of select="."/>
      > </xsl:when>
      > <xsl:otherwis e>
      > <meta content="{.}" name="{local-name()}"/>
      > </xsl:otherwise>
      > </xsl:choose>
      > </xsl:for-each>
      >
      Awful.
      >
      >The problem is that it copies the namespace when it does
      >so (it appears to be implied, rather than declared).
      >
      "Implied rather than declared"? What do you mean?
      >
      >So this:
      >>
      ><meta content="abc" name="dc.creato r"/>
      >>
      >becomes this in the final output:
      >>
      ><meta xmlns="http://www.myco.com/datalist" content="yuri"
      >name="dc.creat or"/>
      >
      And what is the problem - the fact that your resulting meta
      element is in http://www.myco.com/datalist namespace, or
      the fact that this namespace is explicitly declared as the
      default namespace on this element?
      >
      >How do I copy the element and not have the namespace in
      >the result?
      >
      You can't. You can only create an element with the same
      name, but not in a namespace.
      >
      I would recommend posting a minimal complete example of your
      problem, since it's not really clear to me what your
      problem is.
      I guess, the problem is that DTDs are not namespace-aware and so the
      result of the transformation is not DTD-valid.

      --
      Johannes Koch
      In te domine speravi; non confundar in aeternum.
      (Te Deum, 4th cent.)

      Comment

      • Pavel Lepin

        #4
        Re: Copying without namespace?


        Johannes Koch <koch@w3develop ment.dewrote in
        <47c7da46$0$580 $6e1ede2f@read. cnntp.org>:
        Pavel Lepin schrieb:
        >Andre-John Mas <andrejohn.mas@ gmail.comwrote:
        >>So this:
        >>>
        >><meta content="abc" name="dc.creato r"/>
        >>>
        >>becomes this in the final output:
        >>>
        >><meta xmlns="http://www.myco.com/datalist"
        >>content="yuri " name="dc.creato r"/>
        >>
        >And what is the problem - the fact that your resulting
        >meta element is in http://www.myco.com/datalist
        >namespace, or the fact that this namespace is explicitly
        >declared as the default namespace on this element?
        >
        I guess, the problem is that DTDs are not namespace-aware
        and so the result of the transformation is not DTD-valid.
        I think someone should start a "Let the DTDs go!" movement,
        would be about time. Hmm, maybe I could, but... hold on for
        a second... Yep. That's my natural laziness kicking in.
        Never mind.

        --
        When all you have is a transformation engine, everything
        looks like a tree.

        Comment

        • Johannes Koch

          #5
          Re: Copying without namespace?

          Pavel Lepin schrieb:
          Namespace prefix declaration
          alone shouldn't break XHTML validation I believe.
          It breaks XHTML DTD validation, because the XHTML DTDs allow the xmlns
          "attribute" on the html element only.

          --
          Johannes Koch
          In te domine speravi; non confundar in aeternum.
          (Te Deum, 4th cent.)

          Comment

          • Joseph Kesselman

            #6
            Re: Copying without namespace?

            Andre-John Mas wrote:
            but how do you exclude an anonymous namespace:
            xmlns=""
            The default namespace declaration is generally not generated into the
            output unless it is required, meaning that the parent element is in a
            different default namespace. I'd have to take another look at your
            specific example to see whether that's what's going on, but if it is
            then the proper answer is "if you don't want to change default
            namespaces, don't output an element that's in a different default
            namespace than its parent."

            --
            Joe Kesselman / Beware the fury of a patient man. -- John Dryden

            Comment

            Working...