xml editor

Supported platforms

Compatible with Windows7 & Mac OS X Snow Leopard

Ready for data server software
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] step-by-step work instructions -- recursive apply-templ ates to create html table


Subject: RE: [xsl] 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

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
Keywords
XML Editor | XML Author | WYSIWYG Editors | Schema Editor | XSD Documentation | XSL/XSLT Editor | XQuery | XML Databases | SVN Client
© 2002-2011 SyncRO Soft Ltd. All rights reserved. | Sitemap | Privacy Policy | This website was created & generated with <oXygen/>®XML Editor