I want to rewrite this xslt piece in XSLT 1.0, which does not support "copy-namespaces".
<xsl:copy-of copy-namespaces="no" select="maml:alertSet/maml:alert" />
How?
Provided that you're using XSLT 2.0, all you have to do is add the xpath-default-namespace attribute on the document element of each stylesheet: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="http://example.com"> ...
XSLT <xsl:copy-of> The <xsl:copy-of> element creates a copy of the current node. Note: Namespace nodes, child nodes, and attributes of the current node are automatically copied as well! Tip: This element can be used to insert multiple copies of the same node into different places in the output.
The namespace http://www.w3.org/1999/XSL/Transform is referred to as "the XSLT namespace". The prefix xsl is conventionally used to refer to this namespace (and is so used both within this document and within the XSLT specification), but it has no special status: any prefix may be used.
The mode attribute allows multiple ways of processing the same XML elements. A template must have a match attribute if wanting to use a mode attribute, so they are not meant for templates relying solely upon the name attribute for calling.
The following mimics the XSLT 2.0 construct:
Create templates in a mode that will re-construct your nodes without namespaces:
<!-- generate a new element in the same namespace as the matched element,
copying its attributes, but without copying its unused namespace nodes,
then continue processing content in the "copy-no-namepaces" mode -->
<xsl:template match="*" mode="copy-no-namespaces">
<xsl:element name="{local-name()}" namespace="{namespace-uri()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()" mode="copy-no-namespaces"/>
</xsl:element>
</xsl:template>
<xsl:template match="comment()| processing-instruction()" mode="copy-no-namespaces">
<xsl:copy/>
</xsl:template>
Apply-templates for the desired element(s) in that mode:
<xsl:apply-templates select="maml:alertSet/maml:alert" mode="copy-no-namespaces"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With