Sorry if I am asking a newbie question, but namespaces are really puzzling to me.
I'm trying to generate a number of SVG documents from a single XML/XSLT.
My stylesheet:
<xsl:stylesheet version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
>
<xsl:output method="xml" indent="yes" name="xml" cdata-section-elements="style"/>
<xsl:template match="/">
<xsl:apply-templates select="//root/menu"/>
</xsl:template>
<xsl:template match="menu">
<xsl:variable name="filename" select="concat(@name,'.svg')"/>
<xsl:result-document href="{$filename}" format="xml">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="basic" id="svg-root" width="482" height="600">
<defs>
<style type="text/css"><![CDATA[rect {
fill: white;
fill-opacity:1;
continues...
This works and produces the following output:
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.1" baseProfile="basic" id="svg-root" width="482" height="600">
<defs>
<style type="text/css"><![CDATA[rect {
fill: white;
fill-opacity:1;
continues...
But I want to be able to specify height and width attributes based on calculated content
I have tried to create "<svg>" as <xsl:element name="svg"><xsl:attribute name="xmlns">http://www.w3.org/2000/svg </xsl:attribute></xsl:element>
This fails as it (xmlspy) won't let me assign the xmlns attribute.
If I don't specify a namespace on the root (svg), xmlns is automagically added to the root <svg> node and all first-level sub nodes are applied with namespace references like the following (see <defs>)
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="basic" id="svg-root" width="482" height="600">
<defs xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<style type="text/css"><![CDATA[rect {
fill: white;
fill-opacity:1;
continues...
How can I specify the needed namespaces on the root svg element and at the same time calculate the values for height and width without superfluous namespace references on first-level sub-branches?