David Carlisle Q expansion
with the following declaration
<?xml version = "1.0" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 03December 1999//EN"
"http://www.w3.org/Graphics/SVG/SVG-19991203.dtd">
none of my templates trigger except the default ones, why?
However... when I remove the doctype line,
my templates trigger quite happily.
Most likely the dtd is using an ATTLIST default to supply
the namespace declaration for the root element, so when you
have the dtd your source document is svg, but when you
remove it is just some random unknown element in the null
namespace that happens to be called `svg'. There is a big
difference to an XML processor.
Look out for the associated namespace in the DTD, and
declare the same namespace in the stylesheet. This one
reads
<!ATTLIST svg
xmlns CDATA
#FIXED 'http://www.w3.org/Graphics/SVG/SVG-19991203.dtd'
For a standalone document you need to have the namespace or
namespaces (SVG also uses the XLink namespace) declared
explicitly.
The templates need to check for svg in the SVG namespace, or
they will find svg in the null namespace
<?xml version = "1.0" ?>
<svg xmlns="http://www.w3.org/Graphics/SVG/SVG-19991203.dtd">
and so on will do the trick.
</svg>
To fix this I now have a default template which tells
me if any element is within a namespace.
<xsl:template match="*">
<xsl:variable name="uri">
<xsl:choose>
<xsl:when test="string(namespace-uri())">
<xsl:value-of select="namespace-uri()"/>
</xsl:when>
<xsl:otherwise>Null Namespace</xsl:otherwise>
</xsl:choose>
</xsl:variable>
**** Namespace URI is: <xsl:value-of select="$uri"/>
Declared on element: <xsl:choose>
<xsl:when test="string(name(..))">
<xsl:value-of select="name(..)"/>
</xsl:when>
<xsl:otherwise>/</xsl:otherwise>
</xsl:choose>/<xsl:value-of select="name()"/>***
</xsl:template>
In order to get them to trigger properly I had to add
xmlns:oeb= "http://some.url"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
as attributes to the stylesheet element, then within the templates
use
<xsl:template match="oeb:doc"> |