xsl-list
[Top] [All Lists]

Re: XSLT2 variables / nodesets and their namespace

2005-01-21 05:10:40

  In XSLT 2, if you create a nodeset as a variable, is there any way to
  make it inherit the stylesheet's default namespace?


That's the wrong question:-)

In XSLT (1 and 2) the namespace of an element is an intrinsic part of
its name, just the same as its local name. Every element node within the
tree of nodes associated with the variable individually has a namespace

When (if) that tree is ever lineraised out as a file the system may (or
may not) choose not to put a namespace declaration on every element
start tag but instead put a single declaration at the top, but this is
purely an output issue and at the discretion of the  XSLT system.

So your question should have been

  How, when generating a temporary document in a variable in XSLT2 do I
  arrange that elements have the same namespace as that declared as teh
  default in the stylesheet.

The answer to this question depends on how you are generating the
elements.

If you use literal result elements or xsl:element then the namespaces
declared in the stylesheet are in scope so the answer is just use a name
without a : and the default namesdpace will be used
eg: <foo> or <xsl:element name="foo">

If you are copying elements from the source then since you are copying
the node you get exactly the name it had before it was copied (including
the same namespace) If this is not what you want, then you don't want to
copy you want to apply templates with a template that matches elements
in one namespace and generates elements in the other.


You didn't say what your source looked like but perhaps your problem
isn't about generating elements at all but with selecting elements:
one example had
      <xsl:copy-of select="head/*"/>
the other had
      <xsl:copy-of select="f:head/*"/>

the first one selects a head element in no-namespace the second selects
an element head in the xhtml namespace. Which element does your source
file have?

In XSLT1 you have no alternative but to use prefixes to select
namespaced elements, but in xslt2 you can make teh first unprefixed form
also select an xhtml head if you use the new
xpath-default-namespace="http://www.w3.org/1999/xhtml";
 attribute on xsl:stylesheet

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
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>
--~--



<Prev in Thread] Current Thread [Next in Thread>