This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: XMTP XML file breaks Saxon and XT


Philip,

>For some reason, both Saxon and XT don't process the document correctly,
>and the xsl:template rules I specify do not get fired. However, when I
>remove the xmlns attributes from the MIME element and remove all
>namespace prefixes from the document, everything works.

When XSLT processors match elements (and attributes), they take account of
the namespace that the element is in.

A good way to think about this is to imagine each of the element names (and
attributes if you want, but I'll focus on elements right now) in both the
XML source and the stylesheet being replaced by its expanded-name.

In your source document, you specify the default namespace (the one with no
prefix) to be "http://www.grovelogic.com/xmtp":

<MIME xmlns:mime="http://www.grovelogic.com/xmtp"
      xmlns="http://www.grovelogic.com/xmtp">
...
</MIME>

This means that within this MIME element, every element is within that
namespace.  Essentially, your Date is actually:

<{http://www.grovelogic.com/xmtp}:Date>
  Tue, 13 Oct 1998 23:33:49 -0400
</{http://www.grovelogic.com/xmtp}:Date>

In your stylesheet, on the other hand, you don't have any namespace
declarations except for xsl.  The default namespace is the null namespace -
no prefix means no namespace.  So your template matching Date maps to:

<xsl:template match="{}:Date" >
 <h1>Date:
  <xsl:apply-templates />
 </h1>
</xsl:template>

You can see, then, that '{}:Date' does not match
'{http://www.grovelogic.com/xmtp}:Date'.

Taking out all the namespace declarations in your XML source works because
it then maps the Date in your XML source to the null namespace as well,
which means that they do match.

What you really want to do is make the Date in your stylesheet have an
expanded name of '{http://www.grovelogic.com/xmtp}:Date'.  To do this, you
have to declare the namespace within the stylesheet.  You can give it any
prefix you want (let's say 'mime', for the sake of argument):

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:mime="http://www.grovelogic.com/xmtp"
                exclude-result-prefixes="mime"
                version="1.0" >
...
</xsl:stylesheet>

[Aside: I've added exclude-result-prefixes="mime" to stop the namespace
being declared in the result - you're only using the mime namespace to
recognise elements in the source, they're never going to be outputted.]

Then you can change your match expression so that it's matching the right
kind of Date (a mime Date):

<xsl:template match="mime:Date" >
 <h1>Date:
  <xsl:apply-templates />
 </h1>
</xsl:template>

You can also do the same for the MIME-matching template which was also
never being fired.  It only appeared to be being fired because the built-in
template does exactly the same as it was doing: applying templates to its
children.

I hope this helps,

Jeni

Dr Jeni Tennison
Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE
tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@epistemics.co.uk


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]