Subject: Re: Using the not() function
From: Brett McLaughlin <bmclaugh@xxxxxxxx>
Date: Tue, 18 Jan 2000 17:26:23 -0600
|
"Mark D. Anderson" wrote:
>
> --On Monday, January 17, 2000 11:23 AM +0000 David Carlisle <davidc@xxxxxxxxx> wrote:
> > No, name() gives the literal prefixed name from the source.
>
> and Michael Kay agrees:
> >Generally speaking, it's best to avoid testing the result of the name()
> >function, because two XML documents that are equivalent except for their
> >choice of namespace prefixes will give different answers. Using
> >"not(self::element3)" is safer.
So am I missing something here? I get errors in processing when I have:
<xsl:template match="my:root">
<xsl:apply-templates select="not(self::my:element)" />
</xsl:template>
on the following document:
<my:root xmlns:my="http://myurl.com">
<my:element />
<my:otherElement />
</my:root>
-Brett
>
> Damn, I wasn't aware of this.
>
> So:
>
> - if you have an expanded name which is a literal, and you want to
> match only on that name in that namespace, then use self::
> xmlns:myprefix = urn:some-uri
> ...
> [self::myprefix:el] <!-- if desired node has a namespace which myprefix expands to -->
> [self::el] <!-- if desired node has no namespace -->
>
> - if you want to match any element which has a particular local name,
> regardless of namespace, use local-name():
> [local-name() = 'el']
>
> - if you want to match a local name against a variable, that is easy:
> <xsl:variable name="local_elname" select="'el'"/>
> ...
> [local-name() = $local_elname]
>
> - if you want to match an expanded name against a variable, that is hard:
> <xsl:variable name="local_elname" select="'el'"/>
> <xsl:variable name="ns_el" select="'urn:some-uri'"/>
> ...
> [local-name() = $local_elname and namespace-uri() = $ns_el]
>
> - if you want to match qnames, that is easy but not what you want:
> <xsl:variable name="q_elname" select="'myprefix:el'"/>
> ...
> [name() = $q_elname]
>
> Did i get that right?
>
> -mda
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|