RE: [xsl] Namespace problem

Subject: RE: [xsl] Namespace problem
From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx>
Date: Fri, 25 Sep 2009 03:27:06 +1200
Hi Martin

As far as I know I am copying nodes where the namespace is in scope.

Simple input XML (test.xml):
----
<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:noNamespaceSchemaLocation="../../xml_utils/hcdocs.xsd" index="N"
mark="Y">
<title>Software development</title>
<section>
<title id="Head">Q.A. Cycle</title>
<steps>
<step>Test application</step>
<step>Isolate problem</step>
<step>Submit bug report</step>
<step>Wait a while</step>
<step>When anything happens, go back to step 1</step>
</steps>
</section>
</document>
----

Drastically cut down XSL (test.xsl):
----
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:xmlns="http://www.w3.org/2001/XMLNamespace";
exclude-result-prefixes="xsi">
<xsl:output doctype-system="../../xml_utils/fmdocs.dtd" method="xml"
encoding="UTF-8" />

<xsl:template match="/">
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="node()">
  <xsl:copy>
    <xsl:apply-templates select="@*" />
    <xsl:apply-templates select="node()" />
  </xsl:copy>
</xsl:template>

<xsl:template match="@*">
  <xsl:copy />
</xsl:template>

<!-- suppress default attributes -->
<xsl:template match="@mark|@formatted|@xml:space" />

<!-- Frame uses DTD not XSD -->
<!--xsl:template match="@*[namespace::*]" /-->
<xsl:template match="@xmlns:xsi" />
<xsl:template match="@xsi:noNamespaceSchemaLocation" />

</xsl:stylesheet>
----

Output:
----
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document SYSTEM "../../xml_utils/fmdocs.dtd">
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; index="N">
<title>Software development</title>
<section>
<title id="Head">Q.A. Cycle</title>
<steps>
<step>Test application</step>
<step>Isolate problem</step>
<step>Submit bug report</step>
<step>Wait a while</step>
<step>When anything happens, go back to step 1</step>
</steps>
</section>
</document>
----

Desired output:
----
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document SYSTEM "../../xml_utils/fmdocs.dtd">
<document index="N">
<title>Software development</title>
<section>
<title id="Head">Q.A. Cycle</title>
<steps>
<step>Test application</step>
<step>Isolate problem</step>
<step>Submit bug report</step>
<step>Wait a while</step>
<step>When anything happens, go back to step 1</step>
</steps>
</section>
</document>
----



-----Original Message-----
From: Martin Honnen [mailto:Martin.Honnen@xxxxxx] 
Sent: Friday, 25 September 2009 3:05 a.m.
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Namespace problem

Trevor Nicholls wrote:

> If I could use XSL 2.0 it would be easy, but unfortunately this stylesheet
> is run as part of FrameMaker's XML document load process, and it is thus
> limited to XSL 1.0 (Xalan, there is no alternative). Is there a version of
> your solution that would work in XSL 1?

First we need to understand where the namespace declaration in your 
result comes from, whether it is copied from the input document or 
whether it is simply copied from the stylesheet you have (in which case 
Andrew's suggestion with exclude-result-prefixes="xsi" should suffice).

Are you copying nodes from the input document where the namespace 
declaration is in scope?


-- 

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread