Re: [xsl] Namespaces in output

Subject: Re: [xsl] Namespaces in output
From: "Imsieke, Gerrit, le-tex gerrit.imsieke@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 22 Sep 2021 13:51:36 -0000
You need to omit xmlns="http://www.w3.org/1999/xhtml"; in your stylesheet.

In addition, if you use an identity template, modify it like this:

<xsl:template match="*">
  <xsl:element name="{local-name()}">
    <xsl:apply-templates select="@*, node()" mode="#current"/>
  </xsl:element>
</xsl:template>

Instead of local-name() you can also use name() if the HTML elements donbt have a namespace prefix.

If you have modifying stylesheets, use the same xsl:element instructions instead of xsl:copy.

Gerrit

On 22.09.2021 15:43, Terry Ofner tdofner@xxxxxxxxx wrote:
I am processing html exported from InDesign documents. As such, Every html document comes with the standard doctype and namespace declarations:

<!DOCTYPE html>
<htmlxmlns="http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>">

In the past, I have skirted the namespace tangle by manually removing the doctype and replacing <htmlB xmlns="http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>b> with an element name that the Oxygen xslt engine would not quibble about, such as <mybook>. Since I have too many documents to transform, I have left the doctype and html/namespace in place and modified the stylesheet namespace declarations like this:

<xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/Transform <http://www.w3.org/1999/XSL/Transform>"
B B version="3.0"
B B xmlns="http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>"
B B xpath-default-namespace="http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>"
xmlns:map="http://www.w3.org/2005/xpath-functions/map <http://www.w3.org/2005/xpath-functions/map>"
xmlns:xs="http://www.w3.org/2001/XMLSchema <http://www.w3.org/2001/XMLSchema>"
xmlns:saxon="http://saxon.sf.net/ <http://saxon.sf.net/>"
B B exclude-result-prefixes="xs map #default saxon">



Well and good. I can address the html elements directly in my stylesheet. However, the namespace http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml> appears in the root level element of all output documents:


<divxmlns="http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>"class="apE">
<pclass="subhead_ap_topic">2.2 Yada Yada</p>
<pclass="subhead_ap_h2">Yuda</p>
<pclass="body_first">NNNN</p>
<pclass="subhead_ap_h4">MMMM</p>
<pclass="body_text">PPPP</p>
</div>


When I remove the namespace at the root level using <xsl:elementB name=bdivbB namespace="">, the http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml> namespace appears on all child elements:

<divclass="apE">
<pxmlns="http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>"class="subhead_ap_topic">2.2 Yada Yada</p>
<pxmlns="http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>"class="subhead_ap_h2">Yuda</p>
<pxmlns="http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>"class="body_first">NNNN</p>
<pxmlns="http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>"class="subhead_ap_h4">MMMM</p>
<pxmlns="http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>"class="body_text">PPPP</p>
</div>


My question: Is it possible to remove all namespaces from my result documentsbshort of selecting * and rebuilding all elements using <xsl:element namespace=bb>? These namespace declarations donbt hamper the display of the resulting documents. However, text is text and the extra load, over pages and pages of such output canbt but add time to rendering pages. Of course, having one namespace declaration at the root level is preferable to having all child elements carrying a ns.

Any help in this would be appreciated.

Terry

Current Thread