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

generalisation of template

Subject: generalisation of template
From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Thu, 17 Jan 2002 10:32:32 -0000
templates generalisation
Hi all,

I think Ive already asked this one but it didnt get any takers... maybe this
time :)

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?

The template looks like:

<xsl:template match="mpl0|mpl1|mpl2|mpl3|mpl4">
<xsl:param name="last" select="0"/>
<xsl:choose>
   <xsl:when test="( $last + position() ) mod 2 = 1">
     <xsl:call-template name="row_even"/>
   </xsl:when>
   <xsl:otherwise>
     <xsl:call-template name="row_odd"/>
   </xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="mpl1|mpl2|mpl3|mpl4">
   <xsl:with-param name="last" select="$last + last()"/>
</xsl:apply-templates>
</xsl:template>

And the data structure looks like:
(Basically, the next level of nesting is always the last element of the last
node of the previous level)

<mpl0>
  <n>Level 0</n>
</mpl0>
<mpl0>
  <n>Level 0</n>
  <mpl1>
    <n>Level 1</n>
  </mpl1>
  <mpl1>
    <n>Level 1</n>
  </mpl1>
  <mpl1>
    <n>Level 1</n>
  </mpl1>
  <mpl1>
    <n>Level 1</n>
    <mpl2>
      <n>Level 2</n>
    </mpl2>
    <mpl2>
      <n>Level 2</n>
      <mpl3>
        <n>Level 3</n>
      </mpl3>
    </mpl2>
  </mpl1>
</mpl0>

Output should be something like:

Level 0
>Level 0
.Level 1
.Level 1
.Level 1
>.Level 1
..Level 2
>..Level 2
...Level 3

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

Thanks

andrew

===


 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.