namespace conflict

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
david_himself
Posts: 10
Joined: Mon Oct 01, 2018 7:29 pm

namespace conflict

Post by david_himself » Thu Feb 14, 2019 11:50 am

Beginner's confusion about the namespace of an XML and perhaps of an XSLT. This post overlaps with several previous posts, but I couldn't be sure I'd found the appropriate fix in them. Apologies if already answered.

I have a set of XML files which reference an XSLT file and a Relax NG schema, as follows, and which validate fine:

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="../style/HAM_stylesheet.xsl"?><?xml-model href="HAM_TEI_schema.rnc" type="application/relax-ng-compact-syntax"?><TEI xmlns="http://www.tei-c.org/ns/1.0">

The XSLT and the schema each also separately validate. The XSLT has this, and none of the elements in its body have prefixes:

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html"/>

Whether the Relax NG schema is created with a prefix set for pattern names or without one seems to make no difference whatsoever when editing the XMLs in Oxygen. I don't understand this, but it isn't currently a problem.

My problem is this. When the XMLs are processed to HTML, the XSLT fails to take any data from the specific XML. But add quite literally any prefix at all to the XML's namespace, e.g. <TEI xmlns:RUBBISH="http://www.tei-c.org/ns/1.0">, and the processing works perfectly and fully populates the display. So we have the minor inconvenience of having to add a prefix to each XML for uploading but subtract it again for further editing. Is there a one-off fix that would allow an XML to be used in the same form both in Oxygen and on our website (which I'm sure is the normal situation)? And if so, do I really have to go through the whole XSLT adding a prefix to every element? I don't want to embark on that unless I know for sure that (i) it will work, and (ii) it's really necessary. Finally, what then would be the correct way to create the schema: with or without prefix? Thanks.

David

adrian
Posts: 2581
Joined: Tue May 17, 2005 4:01 pm

Re: namespace conflict

Post by adrian » Thu Feb 14, 2019 1:49 pm

Hi,
My problem is this. When the XMLs are processed to HTML, the XSLT fails to take any data from the specific XML. But add quite literally any prefix at all to the XML's namespace, e.g. <TEI xmlns:RUBBISH="http://www.tei-c.org/ns/1.0">, and the processing works perfectly and fully populates the display.
This works because you're inadvertently breaking the default namespace of the document (xmlns="namespace").
To clarify, xmlns="http://www.tei-c.org/ns/1.0" means the default namespace (the namespace of all elements without prefix) is "http://www.tei-c.org/ns/1.0".
If there is no xmlns="namespace" declaration, it means that the default namespace is "no namespace".
When you say you're adding a prefix to the XML namespace (xmlns:RUBBISH="http://www.tei-c.org/ns/1.0"), you are actually altering the default namespace declaration (xmlns="namespace"). So, after this change the elements from the XML document are in "no namespace" (the RUBBISH prefix is not used, so it is ignored) and that's why the XSLT that is not namespace-aware starts to work.
Is there a one-off fix that would allow an XML to be used in the same form both in Oxygen and on our website (which I'm sure is the normal situation)? And if so, do I really have to go through the whole XSLT adding a prefix to every element? I don't want to embark on that unless I know for sure that (i) it will work, and (ii) it's really necessary.
There is no way to easily fix this in XSLT 1.0, you have to fix the namespace (use a prefix) for elements in XSLT. Oxygen doesn't provide an option to ignore the namespace. You will most likely want to stick to XSLT 1.0 if you want it to still work on the web site. Most web browsers only properly support XSLT 1.0.
The alternative is to make a copy of the XSLT, switch it to XSLT 2.0 (xsl:stylesheet version="2.0") and specify on the xsl:stylesheet root xpath-default-namespace="http://www.tei-c.org/ns/1.0" (all elements without prefix are assumed to be from this namespace). You can then use this XSLT 2.0 stylesheet with Oxygen. In Oxygen you can create a transformation scenario that specifies your alternative stylesheet (use Saxon-PE as the transformer).
Finally, what then would be the correct way to create the schema: with or without prefix?
The prefix within the schema doesn't matter as long as the namespace is indicated correctly.
Check if your schema in the current form actually validates your document. Break something in the XML that you know should be flagged as an error and see if it is reported by the validation.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

david_himself
Posts: 10
Joined: Mon Oct 01, 2018 7:29 pm

Re: namespace conflict

Post by david_himself » Thu Feb 14, 2019 11:13 pm

Many thanks for quick reply. My preferred solution, given that the website has server-side processing, is for a suitable XSLT 2.0 processor to be used.

Is there any merit in XSLT 1.0 solutions which create a new root element and a set of new elements which copy the existing elements but give them their local names?

Otherwise I'll add prefixes as you say, though I'm not sure whether this goes for attributes, parameters, etc. as well as elements.

best
David

adrian
Posts: 2581
Joined: Tue May 17, 2005 4:01 pm

Re: namespace conflict

Post by adrian » Fri Feb 15, 2019 7:17 pm

Hi,

Usually only the elements are in a namespace. For the TEI document format only the elements are in that namespace.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Post Reply