[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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
html whitespace handling text
"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?

No.
 
> 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'/>
           </a>
        </xsl:for-each>
</xsl:template>

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
xml:space='preserve'.

> 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).

James


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.