Re: [xsl] Global namespace prefixes (Corrected Examples)

Subject: Re: [xsl] Global namespace prefixes (Corrected Examples)
From: Nathan Potter <ndp@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 13 Nov 2008 22:14:34 -0800
I wored out the XSLT Extension stuff, so Now my test transform looks like this:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xalan="http://xml.apache.org/xalan";
xmlns:exslt="http://exslt.org/common";
xmlns:dap="http://xml.opendap.org/ns/DAP/3.2#";
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
>
<xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes'/>


<xsl:variable name="dummy">
<xsl:element name="att:dummy" namespace="{/dap:Dataset/@base}/ att#"/>
</xsl:variable>



<xsl:template match="dap:Dataset" >
<rdf:RDF>
<xsl:copy-of select="exslt:node-set($dummy)// namespace::*"/>
<xsl:apply-templates />
</rdf:RDF>


</xsl:template>

<xsl:template match="dap:Attribute" >
<xsl:element name="{@name}" namespace="{/dap:Dataset/@base}/ att#"><xsl:value-of select="." /></xsl:element>
</xsl:template>



</xsl:stylesheet>




And I get this error:


ERROR: 'com.sun.org.apache.xalan.internal.xsltc.TransletException: org.jdom.IllegalAddException: The namespace xmlns="http://base.document/att# " could not be added as a namespace to "rdf:RDF": The namespace prefix "" collides with an additional namespace declared by the element'
org.jdom.transform.XSLTransformException: Could not perform transformation: com.sun.org.apache.xalan.internal.xsltc.TransletException: com.sun.org.apache.xalan.internal.xsltc.TransletException: org.jdom.IllegalAddException: The namespace xmlns="http://base.document/att# " could not be added as a namespace to "rdf:RDF": The namespace prefix "" collides with an additional namespace declared by the element



Which seemed odd until I dump out my dummy element:


<xsl:copy-of select="$dummy"/>

Which produces:

<dummy xmlns="http://base.document/att#"; />



So despite the fact that I assigned a namespace prefix when I created $dummy, the XSLT processor appears to ignore it.



Nathan


On Nov 13, 2008, at 5:25 PM, Nathan Potter wrote:

I don't understand how to do this thing with node-set. When I try this:



<xsl:variable name="dummy">
<xsl:element name="att:dummy" namespace="{/dap:Dataset/@base}/ att#"/>
</xsl:variable>



<xsl:template match="dap:Dataset" >
<rdf:RDF>
<xsl:copy-of select="exslt:node-set($dummy)// namespace::*"/>
<xsl:apply-templates />
</rdf:RDF>
</xsl:template>


I get a "Namespace prefix 'exslt' is undeclared." error when I compile the stylesheet. Which isn't surprising, since it is missing and I suspect the crux of this trick is in setting the prefix correctly.



============================================================ Nathan Potter Oregon State University, COAS ndp at coas.oregonstate.edu 104 Ocean. Admin. Bldg. 541 737 2293 voice Corvallis, OR 97331-5503 541 737 2064 fax

Current Thread