[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] namespace problem

Subject: Re: [xsl] namespace problem
From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 11 Sep 2014 12:49:29 -0000

Hi Ruud,

While in Wolfgang's demo, he declared the default namespace repeatedly
-- probably in order to demonstrate how to do so -- in his solution he
could have done just what you did, with a single declaration at the
top. In that case, it would be in scope throughout the document (not
just in the fragments where it was declared), only overridden in the
single place where another declaration claimed the same prefix (or
lack of a prefix, in this case).

As to your question (how to match in the xhtml namespace only), one
helpful insight could be that the prefixes used in the XSLT do *not*
have to be the same as the prefixes used in the source documents
(which, indeed, may not always be consistent with one another either).
Or anywhere else. Only the namespaces must correspond; the prefixes
are only a way to get to the namespaces.

So neither of these would match 'char' in no namespace; one matches
'char' in the xhtml namespace ... and so does the other:

<xsl:template match="char"
   ... matches 'char' in the xhtml namespace

<xsl:template match="xh:char"
  ... matches 'char' in ... the xhtml namespace

Indeed, a helpful processor, when it sees both of these together in
the same XSLT, will warn you that you have a template clash. (Try it.

Cheers, Wendell

On Mon, Sep 8, 2014 at 3:57 AM, Ruud Grosmann r.grosmann@xxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> On 09/05/14 17:24, Wolfgang Laun wolfgang.laun@xxxxxxxxx wrote:
>> Hi Ruud,
>> I'm not sure what you misunderstood, but here's the XSLT that does what
>> you
>> want. I've added a couple of comments to indicate what goes on where.
> hi Wolfgang,
> thank you for your patience. Your reply was exactly what I needed to
> understand what is going on.
> The solution in your mail is not what I was looking for, because it would
> have meant that I would have to insert the namespace in each starttag. The
> transform I am working with has a lot of starttags already so that would
> have been very laborious.
> The other way around is in my case a lot more attractive, that is explicitly
> putting the contents of the variable in the no namespace. As you explained,
> because of the namespace on the root element of the transform, the variable
> ended up having that namespace too, and the match was doing a no namespace
> match.
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:transform version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns="http://www.w3.org/1999/xhtml"
>                         xmlns:xs="http://www.w3.org/2001/XMLSchema"
>                         exclude-result-prefixes="xs xsl">
>   <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" />
>   <xsl:template match="/">
>     <document>
>       <xsl:apply-templates/>
>     </document>
>   </xsl:template>
>   <xsl:template match="p">
>     <xsl:variable name='blip'>
>       <xsl:apply-templates />
>     </xsl:variable>
>     <xsl:apply-templates select='$blip' mode='pass2' />
>   </xsl:template>
>   <xsl:template match="Char">
>     <!-- put explicitly in no namespace. -->
>     <char xmlns=''><xsl:apply-templates /></char>
>   </xsl:template>
>   <xsl:template match='char' mode='#all'>
>     <c><xsl:apply-templates /></c>
>   </xsl:template>
> </xsl:transform>
> I am still wondering what the solution should have been when I only wanted
> to change the match. So how could I have matched a char element in the
> http://www.w3.org/1999/xhtml namespace only?
> I saw that doing a match on '*:char' made the transform work, but I didn't
> like the idea of that approach.
> thanks anyhow, very glad with your help!
> regards, Ruud

Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables

Current Thread