Re: [xsl] a namespace problem

Subject: Re: [xsl] a namespace problem
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 3 Apr 2002 18:24:08 +0100
Hi Bryan,

>>To get what you expect, simply choose an arbitrary namespace prefix
>>for your default namespace, and use that in expressions...
>
> would be counter-productive to go through the trouble of doing that
> as I'm gonna be downloading the rss periodically.
>
> Darn I just know it's gonna turn out having to be something with
> matching against the local-name().

I think perhaps you've misunderstood what Dion was saying. You don't
have to worry about changing the RSS documents - just declare the RSS
namespace in your stylesheet, with some prefix, and use that prefix
for matching/selecting the nodes:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
                xmlns:rss="http://purl.org/rss/1.0/";
                ...>

<xsl:template match="rdf:RDF">
  <xsl:apply-templates select="rss:channel" />
</xsl:template>

<xsl:template match="rss:channel">
  <h3 title="{rss:description}">
    <a href="{rss:link}"><xsl:value-of select="rss:title"/></a>
  </h3>
  <xsl:apply-templates/>
</xsl:template>

...

</xsl:stylesheet>

For example rss:channel matches/selects channel elements in the RSS
namespace. It doesn't matter what prefix was used in the RSS document
itself. As far as the XSLT processor is concerned, the RSS document:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
         xmlns="http://purl.org/rss/1.0/";
         ...>

<channel rdf:about="http://www.bizreport.dk";>
  ...
</channel>
...
</rdf:RDF>

is more or less exactly the same as the RSS document:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
         xmlns:rss="http://purl.org/rss/1.0/";
         ...>

<rss:channel rdf:about="http://www.bizreport.dk";>
  ...
</rss:channel>
...
</rdf:RDF>

and more or less exactly the same as the RSS document:

<wibble:RDF xmlns:wibble="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
            xmlns:foo="http://purl.org/rss/1.0/";
            ...>

<foo:channel wibble:about="http://www.bizreport.dk";>
  ...
</foo:channel>
...
</wibble:RDF>

Namespace prefixes (or lack of them) in the XML document don't matter.
Namespace prefixes in the XSLT document don't matter, but if you want
to refer to an element or attribute in a namespace then you must
associate some kind of prefix with that namespace.

There's absolutely no need to use local-name() in this situation.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread