Saxon: namespace-alias removes the required xmlns attribute

Here should go questions about transforming XML with XSLT and FOP.
katzlbt
Posts: 3
Joined: Fri Oct 17, 2008 11:49 am

Saxon: namespace-alias removes the required xmlns attribute

Post by katzlbt »

I have the problem to create SVG output with XSLT Saxon8 that should look like following snippet, but I cannot get the xmlns attribute into the output!

Code: Select all


<!DOCTYPE svg
PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="1280" xmlns="http://www.w3.org/2000/svg" version="1.1">
With the following INCLUDED in the XSLT the attribute xmlns="http://www.w3.org/2000/svg" is removed from the result at any spot and cannot be included (not using exclude-result-prefixes for svg).

Code: Select all


<xsl:namespace-alias stylesheet-prefix="svg" result-prefix="#default"/>
With exactly this line REMOVED in the XSLT the result looks like that and gives errors in Xerces (Element type "svg:svg" must be declared):

Code: Select all


<!DOCTYPE svg:svg
PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="100%" height="1280" version="1.1">
<svg:g transform="translate(0,0)">
Any hints are appreciated!
Thanks for any help & hints!
I am using Oxygen 8.2, but upgraded the saxon jars to the latest.

----

Code: Select all

<xsl:stylesheet version="2.0" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:svg="http://www.w3.org/2000/svg"
exclude-result-prefixes="fn xs">
<xsl:output
method="xml"
doctype-public="-//W3C//DTD SVG 1.0//EN"
doctype-system="http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
media-type="image/svg+xml"
version="1.0"
xmlns="http://www.w3.org/2000/svg"
indent="yes"/>

<!--<xsl:namespace-alias stylesheet-prefix="svg" result-prefix="#default"/>-->

<xsl:template match="/">
<svg:svg width="100%" height="100%" version="1.1">
<xsl:apply-templates select="...."/>
</svg:svg>
</xsl:template>
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Saxon: namespace-alias removes the required xmlns attribute

Post by sorin_ristache »

Hello,
katzlbt wrote:I have the problem to create SVG output with XSLT Saxon8 that should look like following snippet, but I cannot get the xmlns attribute into the output!

Code: Select all


<!DOCTYPE svg
PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="1280" xmlns="http://www.w3.org/2000/svg" version="1.1">
When you use

Code: Select all

<xsl:namespace-alias stylesheet-prefix="svg" result-prefix="#default"/>
I think Saxon should add the declaration of the default namespace xmlns:svg="http://www.w3.org/2000/svg" in the result of the transformation:

Code: Select all

<svg xmlns="http://www.w3.org/2000/svg" ...
The specification says that "In the event that the same URI is used as a literal namespace URI and a target namespace URI, the second of these rules takes precedence." It seems it is a Saxon bug. To avoid it you should set the default namespace to the SVG namespace in the stylesheet:

Code: Select all

<xsl:stylesheet version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2000/svg"
exclude-result-prefixes="fn xs">

...


<xsl:template match="/">
<svg width="100%" height="100%" version="1.1">
<g transform="translate(0,0)"/>
</svg>
</xsl:template>
</xsl:stylesheet>
Regards,
Sorin
katzlbt
Posts: 3
Joined: Fri Oct 17, 2008 11:49 am

Re: Saxon: namespace-alias removes the required xmlns attribute

Post by katzlbt »

Thanks alot! :)
This really produced the desired result.
I thought I had tried that too, but apparently I haven't.

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2000/svg"
exclude-result-prefixes="fn xs">
<xsl:output
method="xml"
doctype-public="-//W3C//DTD SVG 1.1//EN"
doctype-system="http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
media-type="image/svg+xml"
xmlns="http://www.w3.org/2000/svg"
indent="yes"/>

... no alias ...

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg
PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="300" version="1.1">
Post Reply