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

Re: Re: not simple (or simple? :-) xpath matching

Subject: Re: Re: not simple (or simple? :-) xpath matching
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 7 Jun 2001 21:03:35 +0100
Re:  Re: not simple (or simple? :-) xpath matching
Hi Daniel,

> now, i want to have a default chapter, if given is incorrect and
> print a short information, that one asked for non-existent.

Sure. In that case finding the chapter that's been requested is very
similar to before, using @name rather than @id - you want the part
whose @name is equal to the $part parameter and, within that, the
chapter whose @name is equal to the $chapter parameter:

  part[@name = $part]/chapter[@name = $chapter]

If you store the result of that expression in a variable, then you
have a variable that has an empty node set if there is no such
chapter:

  <xsl:variable name="part-element" select="part[@name = $part]" />
  <xsl:variable name="chapter-element"
                select="$part-element/chapter[@name = $chapter]" />

You can then use xsl:choose/xsl:when to test whether there is such a
chapter, and if it isn't then give a bit of explanatory text:

  <xsl:choose>
     <xsl:when test="$chapter-element">
        <xsl:apply-templates select="$chapter-element" />
     </xsl:when>
     <xsl:otherwise>
        Sorry, you asked for rather impossible chapter.
        Here's the first chapter in
        '<xsl:value-of select="$part" />':
        <xsl:apply-templates select="$part-element/chapter[1]" />
     </xsl:otherwise>
  </xsl:choose>

I hope that helps,

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.