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

Re: template's match-set ? (feature request?)

Subject: Re: template's match-set ? (feature request?)
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 6 Sep 2002 14:19:17 +0100
template match
Hi Rob,

> I was looking for the following functionality in the draft for
> XSLT2, but could not find it. It seems like it is possible.
>
> Anyway, what I want to do is have a 'match-set' (sort of like
> attribute-set) that I can 'use-match-set' on various templates with
> different modes.

Hmm... no, there isn't anything similar to what you're proposing in
XSLT 2.0. However, I can think of a couple of ways that you could
achieve what you want to achieve.

The first will work in both XSLT 1.0 and XSLT 2.0. You set up a key
that matches the things that you want to match, and indexes them by a
static string (which could in fact be empty, but let's use something a
bit more meaningful):

<xsl:key name="match-set" match="article | faq | job"
         use="'content-pieces'" />

You can then create templates that match these elements by using the
key() function in the match attribute of the template. For example:

<xsl:template match="key('match-set', 'content-pieces')"
              mode="mode-1">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="key('match-set', 'content-pieces')"
              mode="mode-2">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="key('match-set', 'content-pieces')"
              mode="mode-n">
  <xsl:apply-templates/>
</xsl:template>

These templates will match anything that's matched by the
'match-set' key and takes the value 'content-pieces'. You could have
other key definitions, also for the 'match-set' key, that matched
different kinds of nodes and gave different values for them if you
wanted.

The second, in XSLT 2.0 or using func:function from EXSLT with XSLT
1.0, is to create a function that returns true if a node is part of
the set that you want to match and false if not. Something like:

<xsl:function name="my:is-content-piece">
  <xsl:param name="node" select="/.." />
  <xsl:result select="self::article or self::faq or self::job" />
</xsl:function>

and then call that function from a predicate in the match patterns:

<xsl:template match="*[my:is-content-piece(.)]" mode="mode-1">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="*[my:is-content-piece(.)]" mode="mode-2">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="*[my:is-content-piece(.)]" mode="mode-n">
  <xsl:apply-templates/>
</xsl:template>

These templates match any element for which the my:is-content-piece()
extension function returns true, which is only the case for article,
faq or job elements.

I must say that I do like the first method, but perhaps it's a little
hacky. It's more obvious how the second method works.

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.