[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [xml] XSLT question, regarding RSS



On Wed, Apr 28, 2004 at 09:30:47PM -0700, Colin Fox wrote:
> It doesn't actually "successfully" execute, since the "item" node is
> unrecognized. 

I meant that your XSLT script actually runs, and doesn't give an error.

> I guess this is where I went wrong. I'm a little unclear on how the lack
> of a namespace specifier works, then.

> This default namespace doesn't have a name, so how am I supposed to
> create an XSLT stanza that 'answers' to it, other than by not including
> a namespace?

> How do you specify an explicit namespace without a prefix? By explicit
> prefix you mean:
> 
> <rss:item>
> 
> where rss is the prefix, right? What is a prefix-less explicit namespace?

Namespace prefixes simply provide a way to associate a local name with a
namespace.  You can map any prefix you want to a particular namespace
and then use that prefix on elements, and the result will be equivalent
to any different possible prefix used.  For example:

<rss:item xmlns:rss="http://purl.org/rss/1.0/"/>

is exactly the same as

<item xmlns="http://purl.org/rss/1.0/"/>

is exactly the same as

<xyz:item xmlns:xyz="http://purl.org/rss/1.0/"/>

And so you could match the RSS item element with an XSLT template using
something like the following:

<xslt:template xmlns:xslt="http://www.w3.org/1999/XSL/Transform";
               xmlns:rss="http://purl.org/rss/1.0/";
               match="rss:item"/>

or, equivalently:


<xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
              xmlns="http://purl.org/rss/1.0/";
              match="item"/>

Both of which would match any of the three RSS items above.

The key point is that you must tell your XML what namespace things are
in using a prefix mapping (or the default namespace), else it will
presume that unprefixed elements are in the empty namespace (as in your
previous XSLT script).

Take care,

    John

Attachment: pgpo9lsyF9M9t.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]