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

RE: generalisation of template

Subject: RE: generalisation of template
From: "Andrew Welch" <andrew@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 18 Jan 2002 10:50:25 -0000
RE:  generalisation of template
Thanks Jeni, great as always

(and it always seems so simple once its in front of me...)

I think I need to test that substring-after really is a number as my
templates that match 'mplhead' and 'mpldata' are no longer being
matched/called.  What is the best way of doing this?

number(substring-after(name(), 'mpl')>=0

seems to do the trick, is this ok?


cheers

andrew

===






-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Jeni Tennison
Sent: Friday, January 18, 2002 10:15 AM
To: Andrew Welch
Cc: XSL-List (E-mail)
Subject: Re:  generalisation of template


Hi Andrew,

> I have this template (c/o Ken) that traverses some nested XML and
> calls row_even or row_odd. The problem is that it uses the actual
> element names (qnames, right?) to recursively make its way through
> the tree. This is fine but a neater (and more future proof) solution
> would be a general template that could be applied to all 'nesting
> depths'. So, can this be done without using 'mplx' and using
> something like 'child[position()=last()][child has child nodes(!)]'
> ?? Can you even call templates in this way?

Rather than having:

> <xsl:template match="mpl0|mpl1|mpl2|mpl3|mpl4">

You could have:

<xsl:template match="*[starts-with(name(), 'mpl') and
                       number(substring-after(name(), 'mpl'))]">

And rather than having:

> <xsl:apply-templates select="mpl1|mpl2|mpl3|mpl4">

You could similarly have:

  <xsl:apply-templates select="*[starts-with(name(), 'mpl') and
                                 number(substring-after(name(),
                                                        'mpl'))]">

Whether you actually want to test whether the substring after the
'mpl' in the name is actually a number is up to you - if you don't
have any other elements in your source document that start with 'mpl'
then you don't have to, of course.

> Also :) If the solution could include outputting a '>' or similar at
> the first element of each level (like a directory + or - ) that has
> child nodes (that have child nodes) then I would be extremely
> greatful

I think that you can do that just by testing the position() of the
node that you're on. So just add something like:

  <xsl:if test="position() = 1">
    <xsl:text> - </xsl:text>
  </xsl:if>

Cheers,

Jeni

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


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 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.