No Output

1. No output problem when using a DTD
2. Output only if a test condition is true


No output problem when using a DTD

David Carlisle

Q expansion

 with the following declaration
<?xml version = "1.0" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 03December 1999//EN" 

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

  xmlns CDATA 
  #FIXED ''

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="">
and so on will do the trick.

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:when test="string(namespace-uri())">
          <xsl:value-of select="namespace-uri()"/>
        <xsl:otherwise>Null Namespace</xsl:otherwise>
      ****   Namespace URI is: <xsl:value-of select="$uri"/>
      Declared on element: <xsl:choose>
        <xsl:when test="string(name(..))">
          <xsl:value-of select="name(..)"/>
      </xsl:choose>/<xsl:value-of select="name()"/>***

In order to get them to trigger properly I had to add

xmlns:oeb= "http://some.url"
xmlns:xsl="" version="1.0">

as attributes to the stylesheet element, then within the templates use

<xsl:template match="oeb:doc">


Output only if a test condition is true

Sara Mitchell

We are converting an XML document to another type of xml document based. Based on data discovered in the process, we do not want to do any further processing.

It sounds like one other approach that might work is simply to start your processing off based on 'ignore' not being present. This uses two templates, rather than one. Using your example, it might look something like this:

<!-- this template matches the nodes you want to ignore
     and does nothing. So it 'skips' them -->
<xsl:template match="basenode[head/tag/@action='ignore']">

<!-- this template matches all basenode nodes that aren't 
     marked to ignore -->
<xsl:template match="basenode[not(head/tag/@action='ignore')]">
<!-- do your processing -->

Chris Bayes offers:

Check out <xsl:message terminate="yes"/>