[xsl] How to stop xalan from deleting namespace declarations

Subject: [xsl] How to stop xalan from deleting namespace declarations
From: Peter Janker <peter.janker@xxxxxx>
Date: Wed, 11 Jun 2003 09:00:11 +0200

Hello All,


I try to write an xslt-script that outputs an xslt-script.
Saxon (6.5.2) and MSXSL(3) seem to work but I have difficulties with the namespace handling within xalan (2_5_0).
Therefore I have three related questions concerning xalan(2-5-0) and the handling of namespace declarations.


1: How can I prevent xalan from deleting its own namespace prefix declaration?
2: How can I prevent xalan from deleting a second namespace prefix declaration for a given namespace?
3: How can I force xalan to explicitely write a namespace declaration within a tag in the output script?
(like: <out:apply-templates xmlns:xalan="http://xml.apache.org/xalan"; select="xalan:nodeset($Var)"/> )


Details:

The command
<xsl:namespace-alias stylesheet-prefix="out" result-prefix="xsl"/>
is used to set the prefix in the output script.
(Saxon and msxsl replace the prefix, xalan uses the prefix 'out' and replaces the URL.)


To handle tree fragments in different environments I want to know the vendor:

<out:variable name="Vendor" select="system-property('xsl:vendor')" />

'xsl' because within the single quotes ('') the prefix is not replaced.

Because of the URI-replacement xalan does not know the xsl prefix.
I thought a workaround would be to declare the namespace either for both prefixes or within the variable tag:
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:out="http://www.w3.org/1999/XSL/Transform";
<out:variable name="Vendor" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; select="system-property('xsl:vendor')" />


<out:apply-templates xmlns:xalan="http://xml.apache.org/xalan"; select="xalan:nodeset($Var)"/>

Unfortunately xalan is always deleting one of the declarations and omittes the inline declaration.
Furthermore xalan is always deleting its own namespace-prefix declaration (xmlns:xalan="http://xml.apache.org/xalan"; ) from the stylesheet-tag and therefore the following lines
in the output script do not work because of an unknown prefix 'xalan'.


<out:choose>
....
   <out:when test="contains($Vendor, 'Apache') ">
       <out:apply-templates select="xalan:nodeset($Var)"/>
   </out:when>
....
</out:choose>


The transformation is started by a batch file with one line:
java -classpath .;D:\jdk1.3.1_04\lib\tools.jar;D:\Xalan\xalan-j_2_5_0\bin\xalan.jar;D:\Xalan\xalan-j_2_5_0\bin\xml-apis.jar;D:\Xalan\xalan-j_2_5_0\bin\xercesImpl.jar org.apache.xalan.xslt.Process -in m2t.xml -xsl m2t.xsl -out xalan_m2T_out.xsl


The generated script xalan_m2T_out.xsl works if one adds the two by xalan omitted declarations.

Thank you for your help.


Peter


--

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


Current Thread