57 captures
23 Mar 2003 - 08 May 2017
Mar APR May
04
2003 2004 2005
success
fail

About this capture

COLLECTED BY

Organization: Alexa Crawls

Starting in 1996, Alexa Internet has been donating their crawl data to the Internet Archive. Flowing in every day, these data are added to the Wayback Machine after an embargo period.

Collection: alexa_dw

this data is currently not publicly accessible.
TIMESTAMPS

The Wayback Machine - http://web.archive.org/web/20040404062420/http://www.xml.com:80/cookbooks/xsltckbk/solution.csp?day=7
 
XML.com

XML.comWebServices.XML.comO'Reilly Networkoreilly.com
  Resources | Buyer's Guide | Newsletter | Safari Bookshelf
   
 O'Reilly Open Source Convention: July 26-30, Portland, OR.
  Topics
Business
Databases
Graphics
Metadata
Mobile
Programming
Schemas
Style
Web
Web Services



   Essentials
Annotated XML
What is XML?
What is XSLT?
What is XSL-FO?
What is XLink?
What is XML Schema?
What is XQuery?
What is RDF?
What is RSS?
What are Topic Maps?
What are Web Services?
What are XForms?
XSLT Recipe of the Day

Manage Your Account
Forgot Your Password?

  Find
Search
Article Archive

Add XML to your Website

  Columns
<taglines/>
Dive into XML
Hacking the Library
Jon Udell
Perl and XML
Practical XQuery
Python and XML
Rich Salz
Sacré SVG
Standards Lowdown
Transforming XML
XML Q&A
XML-Deviant

  Guides
XML Resources
Buyer's Guide
Events Calendar
Standards List
Submissions List

  Toolbox

Syntax Checker



Atom Feed
RSS Feed





   Print.Print
Email.Email article link
The XSLT Cookbook (cover)

XSLT Recipe of the Day

The following recipe is from XSLT Cookbook, by Sal Mangano. All links in this recipe point to the online version of the book on the Safari Bookshelf.

Buy it now, or read it online on the Safari Bookshelf.


You want to select all elements in a specific context, except the ones you choose to exclude.

The best way to select all but a specific element is to say:

<xsl:apply-templates select="*[not(self::element-to-ignore)]"/>

or, if iterating, say:

<xsl:for-each select="*[not(self::element-to-ignore)]">
...
</xsl:for-each>

When XSLT newbies first need to select all but a specific element, they will probably think of the following construct first:

<xsl:apply-templates select="*[name(  ) != 'element-to-ignore']"/>

This code works in many cases, but it could cause trouble when the document uses namespaces. Recall that name( ) returns the node's QName: the namespace prefix concatenated to the local part of the name. However, in any given XML document, nothing forces the author to use a specific prefix:

<!--This will fail if the author decided to use SALES:product instead of 
sales:product -->
<xsl:apply-templates select="*[name(  ) != 'sales:product']"/>

Alternatively, you could use local-name( ). However, this prefix would ignore elements from all namespaces that have that particular local name, which might not be what you want.

This recommendation applies only in the case of elements, not attributes. If you need to select all but a specific attribute, use local-name( ). The self axis, when applied to a name, refers only to elements. In other words, use <xsl:copy-of select=@*[local-name( ) != 'ignored-attribute']/> and not <xsl:copy-of select=@*[not(self::ignored-attribute)]/>.

Finally, just in case of confusion, selecting all but a single element is different from selecting all but a single instance of element. The latter is used in an example discussed earlier in this chapter:

<xsl:apply-templates select="*[generate-id(  ) != generate-id($node-to-ignore)]"/>

Jeni Tennison's book, XSLT and XPath on the Edge (M&T Books, 2001), details when and when not to use name( ) and local-name( ).


View the past week's recipes: Today | Yesterday | 3 days ago | 4 days ago | 5 days ago | 6 days ago | A week ago





Contact Us | Our Mission | Privacy Policy | Advertise With Us | Site Help | Submissions Guidelines
Copyright © 2004 O'Reilly Media, Inc.