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

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

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

> and now i would like to show a chapter depends on parameters in a
> url eg. '?part=c&chapter=4', but also to give the closest one, if
> given is not applicable (to give part=c, chapter=3 in this example,
> or to give part=c, chapter=10 if asked was chapter=12) with simple
> information, that is not exact match. i also need to provide default
> values if parameters are empty (for now i have <xsl:choose>
> construction).

You can set up the parameters with xsl:param elements; if you use the
select attribute or the content of the xsl:param then you can give a
default value for the parameter.  So for example, you could use:

<xsl:param name="part" select="'a'" />
<xsl:param name="chapter" select="1" />

This sets the $part parameter to 'a' by default, and the $chapter
parameter to 1 by default.

As you're using Cocoon, you can set these parameters using the URL you
use to access the XML, as you've indicated.

Then you only want to apply templates to the relevant chapter.  So
within the document-matching template, do:

<xsl:template match="document">
   <xsl:apply-tempates
         select="part[@id = $part]/chapter[@id = $chapter]" />
</xsl:template>

Your example is made a little bit more complicated by the fact that
you want the 'nearest' chapter if there isn't an exact match. For the
nearest before, you want the last chapter whose @id is less than or
equal to the $chapter parameter, which makes the select expression:

  part[@id = $part]/chapter[@id &lt;= $chapter][last()]

For the nearest after, you want the first chapter whose @id is greater
than or equal to the value of the $chapter parameter, so the select
expression is:

  part[@id = $part]/chapter[@id >= $chapter][1]

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.