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

Re: Determining the type of attribute within the match

Subject: Re: Determining the type of attribute within the matching template
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sat, 8 Feb 2003 14:14:36 +0000
template match rdf
Hi James,

> I have a template that catches all element and attribute nodes
>
> <template match="*|@*">
>     <choose>
>         <!-- string literal objects -->
>         <when test="self::text()[normalize-space(.) != '']">
>         </when>
>         <!-- resource types -->
>         <when test="self::@rdf:resource">
>         </when>
>         <!-- datatypes -->
>         <when test="self::@rdf:datatype">
>         </when>
>         <!-- complex objects -->
>         <when test="self::*">
>         </when>
>     </choose>
> </template>
>
> This gives an error with the test self::@rdf:resource

In an expression, the @ is a shorthand for the axis attribute::, so
the above test expands to:

  self::attribute::rdf:resource

i.e. to a step with two axes in it, which isn't allowed.

When you use a name test in a step, the step matches nodes with that
name of the "primary node type" for the axis. For the attribute::
axis, this is attributes, while for the self:: axis (and most other
axes) it's elements. That means that self::rdf:resource always tests
whether the current node is a rdf:resource *element* rather than
attribute, and in fact there is no way to test the name of an
attribute that is the current node aside from with the local-name()
and namespace-uri() functions (and the name() function, but I'd only
use that if you were dealing with attributes in no namespace).

In the case above, I think you'd be a lot better off splitting the
<xsl:choose> into multiple templates:

<xsl:template match="*|@*">
  ...
  <xsl:apply-templates select="." mode="content" />
  ...
</xsl:template>

<!-- string literal objects -->
<xsl:template match="text()[normalize-space(.) != '']" mode="content">
  ...
</xsl:template>

<!-- resource types -->
<xsl:template match="@rdf:resource" mode="content">
  ...
</xsl:template>

<!-- datatypes -->
<xsl:template match="@rdf:datatype" mode="content">
  ...
</xsl:template>

<!-- complex objects -->
<xsl:template match="*" mode="content">
  ...
</xsl:template>

<!-- anything else -->
<xsl:template match="node() | @*" mode="content" priority="-10" />

Cheers,

Jeni

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


 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.