Re: [xsl] Template priority problem

Subject: Re: [xsl] Template priority problem
From: david_n_bertoni@xxxxxxxxxx
Date: Tue, 6 Sep 2005 12:36:48 -0700
> > When people come to this list and say that a template
> > isn't matching when they expect it to, the most common
> > reason is that the elements are in a namespace (typically
> > a default namespace). You haven't shown us the source
> > document, so that's just a guess.
> 

> Yes of course you are right. Damn Default namespace. Whats
> the best approach to solve my problem when all elements in
> the input XML are in a non-blank default namespace? I am
> thinking this may screw up the identity transform template.

No, it doesn't affect the canonical identity transformation.  However, it 
does affect the specialized templates you add to modify the identity 
transformation:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    version="1.0"
    xmlns:foo="http://www.foo.com/foo";>

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="foo:field">
  <!-- Here's where we should do something special... -->
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

Some other comments:

1. "@* | node()" is a less verbose version of "* | comment()
| text() | processing-instruction() | @*"

2. The priority attribute you are using are not necessary.  In most cases, 
the default priorities for match patterns are sufficient.

3. Default namespaces may also affect the XPath expressions you use in 
your xsl:variable definitions.

Dave

Dave

Current Thread