Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Copying without namespace?

Reply
Thread Tools

Copying without namespace?

 
 
Andre-John Mas
Guest
Posts: n/a
 
      02-29-2008
Hi,

I have some code that looks as follows:

<xsl:for-each select="$pageMetaData/*">
<xsl:choose>
<xsl:when test="local-name() = 'meta'">
<xsl:copy-of select="."/>
</xsl:when>
<xsltherwise>
<meta content="{.}" name="{local-name()}"/>
</xsltherwise>
</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.creator"/>

becomes this in the final output:

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

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
 
Reply With Quote
 
 
 
 
Pavel Lepin
Guest
Posts: n/a
 
      02-29-2008

Andre-John Mas <(E-Mail Removed)> wrote in
<(E-Mail Removed)>:
> <xsl:for-each select="$pageMetaData/*">
> <xsl:choose>
> <xsl:when test="local-name() = 'meta'">
> <xsl:copy-of select="."/>
> </xsl:when>
> <xsltherwise>
> <meta content="{.}" name="{local-name()}"/>
> </xsltherwise>
> </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.creator"/>
>
> becomes this in the final output:
>
> <meta xmlns="http://www.myco.com/datalist" content="yuri"
> name="dc.creator"/>


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.
 
Reply With Quote
 
 
 
 
Johannes Koch
Guest
Posts: n/a
 
      02-29-2008
Pavel Lepin schrieb:
> Andre-John Mas <(E-Mail Removed)> wrote in
> <(E-Mail Removed)>:
>> <xsl:for-each select="$pageMetaData/*">
>> <xsl:choose>
>> <xsl:when test="local-name() = 'meta'">
>> <xsl:copy-of select="."/>
>> </xsl:when>
>> <xsltherwise>
>> <meta content="{.}" name="{local-name()}"/>
>> </xsltherwise>
>> </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.creator"/>
>>
>> becomes this in the final output:
>>
>> <meta xmlns="http://www.myco.com/datalist" content="yuri"
>> name="dc.creator"/>

>
> 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.)
 
Reply With Quote
 
Pavel Lepin
Guest
Posts: n/a
 
      02-29-2008

Johannes Koch <(E-Mail Removed)> wrote in
<47c7da46$0$580$(E-Mail Removed)>:
> Pavel Lepin schrieb:
>> Andre-John Mas <(E-Mail Removed)> wrote:
>>> So this:
>>>
>>> <meta content="abc" name="dc.creator"/>
>>>
>>> becomes this in the final output:
>>>
>>> <meta xmlns="http://www.myco.com/datalist"
>>> content="yuri" name="dc.creator"/>

>>
>> 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.
 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      02-29-2008
Johannes Koch wrote:
> I guess, the problem is that DTDs are not namespace-aware and so the
> result of the transformation is not DTD-valid.


DTDs and namespaced XML are incompatable at some pretty basic levels.
Namespace-aware processing assumes that prefixes are purely syntactic
sugar and can be changed at will. DTDs will insist they be nailed down.

The best suggestion I can give you for intermixing the two is to have
your DTD hard-code a default namespace assignment and not use prefixes,
and to have all the elements in the DTD likewise set up that default but
permit it to be explicitly specified in case someone re-asserts it.

The best suggestion I can give you generally is to stop trying to
intermix these, and move to XML Schema.


--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
Andre-John Mas
Guest
Posts: n/a
 
      03-05-2008
On Feb 29, 4:55*am, Pavel Lepin <(E-Mail Removed)> wrote:
> Andre-John Mas <(E-Mail Removed)> wrote in
> <(E-Mail Removed)>:
>
> > * * * <xsl:for-each select="$pageMetaData/*">
> > * * * * <xsl:choose>
> > * * * * * <xsl:when test="local-name() = 'meta'">
> > * * * * * * <xsl:copy-of select="."/>
> > * * * * * </xsl:when>
> > * * * * * <xsltherwise>
> > * * * * * * <meta content="{.}" name="{local-name()}"/>
> > * * * * * </xsltherwise>
> > * * * * </xsl:choose>
> > * * * </xsl:for-each>

>
> Awful.


I am not going argue this point. I am trying to convert code that
claims it was creating xhtml pages (it was creating html), to actually
create xhtml compliant output. There have been plenty of developers
dipping in this code before me.

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

>
> > becomes this in the final output:

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

>
> And what is the problem - the fact that your resulting meta
> element is inhttp://www.myco.com/datalistnamespace, or
> the fact that this namespace is explicitly declared as the
> default namespace on this element?


This name space is something used in the XSL, to refer to a
configuration file specifying localised texts, it is not something
that is meant to be in the output document.

I'll see if I can cobble together an example, but basically what is
being done is copying a block like this, declared in an XML file:

<meta-tags>
<meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57
GMT" />
<meta name="authour" content="the author" />
</meta-tags>

to the output which will be used for rendering the final xhtml page.
For example:

<head>
<title>mypage</title>
<meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT" /
>

<meta name="authour" content="the author" />
</head>

The issue is that I end up with an xhtml document that includes
namespaces that were only meant to be used in the xsl and not the
final document. Having the "http://www.myco.com/datalist" specified
as part of the meta tag just breaks the page.

Andre


 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      03-05-2008
Andre-John Mas wrote:
> The issue is that I end up with an xhtml document that includes
> namespaces that were only meant to be used in the xsl and not the
> final document.


Sounds like you're looking for xsl:stylesheet's exclude-result-prefixes
attribute.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
Pavel Lepin
Guest
Posts: n/a
 
      03-06-2008

Joseph Kesselman <(E-Mail Removed)> wrote in
<47cef74e$1@kcnews01>:
> Andre-John Mas wrote:
>> The issue is that I end up with an xhtml document that
>> includes namespaces that were only meant to be used in
>> the xsl and not the final document.

>
> Sounds like you're looking for xsl:stylesheet's
> exclude-result-prefixes attribute.


Actually, to me it looks more like the OP wants to copy
{meta-data-namespace}meta element as an
{xhtml-namespace}meta element. Namespace prefix declaration
alone shouldn't break XHTML validation I believe. meta
element being in the wrong namespace would, on the other
hand.

--
In Soviet Russia, XML documents transform *you*.
 
Reply With Quote
 
Johannes Koch
Guest
Posts: n/a
 
      03-06-2008
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.)
 
Reply With Quote
 
Pavel Lepin
Guest
Posts: n/a
 
      03-06-2008

Johannes Koch <(E-Mail Removed)> wrote in
<47cfb0a3$0$584$(E-Mail Removed)>:
> 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.


Oops, my fault.

Just reinforces my anti-DTD sentiment, though. I mean,
seriously, in case of XHTML using DTD for validation is
about as bad as using Appendix C for 'compatibility'. Both
mean we cannot freely use XML tools for processing without
a lot of kludgery to make sure nothing 'breaks' in the
pipeline. Kinda defeats the whole point of XML.

--
In Soviet Russia, XML documents transform *you*.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying collection without duplicates Karsten Wutzke Java 7 08-12-2007 11:06 PM
Get RealPlayer to play CDs without copying them MARK WOOLSTON Computer Support 4 09-01-2006 09:43 PM
Copying files without halting on bad ones yawnmoth Computer Information 0 12-22-2005 09:30 AM
Passing large C buffers to Java (via JNI) without copying? jpknott@gmail.com Java 10 10-28-2005 09:33 AM
Adding an embedded resource without copying it? Wysiwyg ASP .Net 0 05-03-2005 10:15 PM



Advertisments