Re: matching on namespaces, whitespace handling

Subject: Re: matching on namespaces, whitespace handling
From: James Clark <jjc@xxxxxxxxxx>
Date: Sat, 12 Jun 1999 15:16:48 +0700
"Wilson, James.W" wrote:
> after banging on XSL (using the latest XT) quite a bit, I have some
> questions for the gurus.
> 1. I don't understand the relationship between the names in the template
> 'match' attributes, the namespaces defined in the input document, and the
> namespaces defined in the stylesheet.

The namespace URIs are matched.  The prefixes are irrelevant.

> Does the processor match 'html:*' using the URI of
> the namespace 'html' defined *in the stylesheet*?

Yes. (Handling of ns:* is bugged in the current version of XT, which is
perhaps what is confusing you.)

> does it match using the
> qname in the original input?

> 2. How do I find all the namespaces that are defined on a node? With the
> namespace() function I can find *the* namespace of a node, but I can't
> figure out how to get *all* defined namespaces.

You can't currently.  This omission is being corrected.

> 3. When producing html output, I often want to control exactly how much
> space is produced between different parts of the result tree. When I want to
> strip out excess space, I can use strip-space='yes' or xml:space='default' -
> BUT this seems to mean 'strip out all but one space' to XT. If I want *no*
> spaces, I have to do something like
> <xsl:template match='foo'>
>         <xsl:for-each select='bar'
>                 xml:space='preserve'
>                 ><a href='{@id}
>                 ><xsl:value-of select='baz'
>                 /></a></xsl:for-each>
> </xsl:template>
> which is hardly a model of readability. ;)

You never need to do that.  That will have exactly the same effect as:

<xsl:template match='foo'>
        <xsl:for-each select='bar'>
           <a href='{@id}'>
              <xsl:value-of select='baz'/>

Whitespace-only text nodes *in the stylesheet* always get stripped
unless you do xml:space='preserve'.  If you want to explicitly output
some whitespace, it's usually easier to use xsl:text then

> Is there another way to
> accomplish this (seemingly trivial) task in a less cramped way?

Whitespace handling can be confusing because it is affected by many
parts of the process:

(a) whitespace in the source document may or may not get stripped
(b) whitespace in the stylesheet may or may not get stripped
(c) whitespace may or may not get added when the result tree is output
as XML

If you find yourself puzzled by whitespace handling, then try removing
any result-ns or indent-result attributes from the stylesheet  That will
prevent any whitespace getting added by (c) and will eliminate
implementation-dependent parts of the process.

If you use the result-ns feature to get HTML 4.0 output rather than XML
output, then the implementation is free to add whitespace in a way it
thinks it thinks fit, provided the whitespace would be ignored according
to the HTML 4.0 spec.  If you don't like the way XT does this, I suggest
you send me an enhancement request (with a complete example).


 XSL-List info and archive:

Current Thread