xsl-list
[Top] [All Lists]

Re: [xsl] Effect of default namespace specifications on imports

2012-10-28 03:36:45
On Sun, Oct 28, 2012 at 1:02 AM, Ihe Onwuka 
<ihe(_dot_)onwuka(_at_)gmail(_dot_)com> wrote:
On Thu, Oct 25, 2012 at 5:04 PM, G. Ken Holman
<gkholman(_at_)cranesoftwrights(_dot_)com> wrote:
At 2012-10-25 16:29 +0100, Ihe Onwuka wrote:

I am writing an XML conversion, part of which entails bringing things
into the new namespace (from no namespace).

I have specified namespace X as my default namespace and my XPath
default namespace but all is not as expected.


I doubt that will work for you.  Your input is in no namespace so any
addressing you need of the input must be in no namespace, so the XPath
default namespace should not be set to anything.


I suspect it is because some elements are handled by an imported
identity template. Although this can be worked around this represents
an opportunity to get some clarification as to what the precise rules
are as relates to default namespace specfications and imported
stylesheets.


There are no such rules regarding a relationship between default namespace
specifications and imported stylesheets.  Each stylesheet fragment is
standalone.  Any use of the XML default namespace or the XPath default
namespace is in scope of only the stylesheet fragment.  There is no
knowledge between stylesheet fragments of the use of the namespaces in other
fragments.

And I suspect the identity template will not help you if you have to change
the namespace for each element.


Here is the algorithm I used to handle renamespacing and other
template processing in a single pass (well it worked for me).

Import the identity template.
Make the new namespace the default namespace of the main stylesheet.

The following template will renamespace all elements  that do not have
an explicit template rule.

  <xsl:template match="*">
    <xsl:element name="{local-name()}">
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template

For your other template rules, any elements that you <xsl:copy> will
stubbornly stay in the old namespace so replace any <xsl:copy>
elements in other templates with <xsl:element name="{local-name()}">.

Above is the ambidextrous solution (XSLT 1.0 and 2.0)

For 2.0 only the <xsl:element name="{local-name}"> can be replaced by
<xsl:copy copy-namespaces="no">

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--