Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Namespaces best practice in XML

From: "andrew welch" <andrew.j.welch@--------->
To:
Date: 4/4/2006 1:44:00 PM
On 4/4/06, tom tom <tomxsllist@xxxxxxxxxxx> wrote:
> My XML Source has a default namespace and never uses prefixes. I am writing
> a stylesheet which  transforms this into XHTML. In the XSLT I (ideally)
> never want to prefix any XHTML output elements or any source XML element
> references.

You will have to do one or the other, as there is only one default
namespace, unless you use two passes with the second pass to put all
the output elements in the xhtml namespace.

eg:

Store the first pass in a variable:

<xsl:variable name="first_pass">
  <xsl:apply-templates/>
</xsl:variable>

Use an identity template put all the elements in the xhtml namespace:

<xsl:template match="*" mode="xhtml">
	<xsl:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml">
		<xsl:copy-of select="@*"/>
		<xsl:apply-templates mode="xhtml"/>
	</xsl:element>
</xsl:template>

Generate your output by applying the identity template to the first pass:

<xsl:template match="/">
  <xsl:for-each select="$first_pass">
    <xsl:apply-templates mode="xhtml"/>
  </xsl:for-each>
</xsl:template>


cheers
andrew


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent