[XSL-LIST Mailing List Archive Home]
Re: [xsl] Namespace de-duplication for dynamically generated elements
Subject: Re: [xsl] Namespace de-duplication for dynamically generated elements|
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Tue, 9 Sep 2008 09:37:10 +0100
> After a long struggle, I've managed some hacky XSLT which manages the
> namespace mapping from strings and NS declarations to prefixed QName
> elements, however I end up getting the xmlns:pt="urn:ex" element on *every*
> leaf element (e.g. <go:zip xmlns:go="urn:ex">), rather than just once on the
> document element as I would like it:
> Does anyone know of any tricks to avoid this situation?
You need to generate the namespace higher up in the tree, either by
creating it manually or by inserting a node that requires it. I would
say the best thing to do is a two pass transform (first pass in a
variable) where the second pass just copies all namespaces to the root
node - a step which tidies the XML for human consumption if you like,
which you can remove down the line if needed.
If you stick with a single pass, you'll need to create the namespace
nodes manually when you output the root node, and then again when you
process further down the tree.