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

RE: step-by-step work instructions -- recursive apply-

Subject: RE: step-by-step work instructions -- recursive apply-templ ates to create html table
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 10 Apr 2003 15:14:19 -0400
work instructions template
Kathy,

For a rather different approach to this, look at

http://www.biglist.com/lists/xsl-list/archives/200304/msg00049.html

It solves a deeper problem than you are faced with (though not much deeper :-), but simplified a bit it could be adapted to what you want to do.


Explanation: consider source like this --

<div><label>1</label>
  <div><label>1.1</label>
    <div><label>1.1.1</label></div>
  </div>
  <div><label>1.2</label></div>
<div>

And templates like this:

A.
<xsl:template match="div">
  <part>
    <xsl:apply-templates/>
  </part>
</xsl:template>

A1.
<xsl:template match="div">
  <part>
    <xsl:apply-templates select="label"/>
  </part>
  <xsl:apply-templates select="div"/>
</xsl:template>

B.
<xsl:template match="label">
  <head>
    <xsl:apply-templates/>
  </head>
</xsl:template>

Templates A and B together make

<part>
  <head>1</head>
  <part>
    <head>1.1</head>
    <part>
      <head>1.1.1</head>
    </part>
  </part>
  <part>
    <head>1.2</head>
  </part>
</part>

Templates A1 and B together make

<part>
  <head>1</head>
</part>
<part>
  <head>1.1</head>
</part>
<part>
  <head>1.1.1</head>
</part>
<part>
  <head>1.2</head>
</part>

which flattens the structure (what your tables look like).

Of course, here the hierarchy is lost. If you want to represent it by some formatting, you can tweak template B like this:

B1.
<xsl:template match="label">
  <head>
    <xsl:for-each select="ancestor::div">
      <xsl:text>#</xsl:text>
    </xsl:for-each>
    <xsl:apply-templates/>
  </head>
</xsl:template>

Which combined with template A1 gives you

<part>
  <head>1</head>
</part>
<part>
  <head>#1.1</head>
</part>
<part>
  <head>##1.1.1</head>
</part>
<part>
  <head>###1.2</head>
</part>

Which displays the hierarchy albeit not reflecting it directly. (Of course IRL the '#' will be spaces for indenting or whatever.)

This is, in effect, the solution Americo is proposing (boiled down).

At 11:52 AM 4/10/2003, you wrote:
Also, just so you don't think I'm TRYING, I'm on my third XSLT book...but I
can't find examples anywhere to match what I've been asking here.

Things are hard to find not only because the topic is complex and explanations are ad hoc, but also because questions are naturally asked by people who do not (yet) know the terminology; hence it's hard to know what to search for.


That's one reason we're here. :->

Good luck,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


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.