Re: Breaking up is hard to do.

Subject: Re: Breaking up is hard to do.
From: "Nikolai Grigoriev" <grig@xxxxxxx>
Date: Mon, 21 Feb 2000 11:24:59 +0300
Steve Muench wrote:

>I'm not sure what you mean by producing a malformed document.
>The result of my example is not ill-formed...
>
>If you know what tags  you need then the exact purpose of
>disable-output-escaping is to let you responsibly put them
>where you need them.

XSLT is primarily meant as a language to transform XML into 
another XML. By standard XSLT techniques, it is simply 
impossible to produce a non-well-formed output; and 
output-escaping techniques can, in principle, be used for such 
a scope. It's more or less like manipulating processor registers
directly from a C code, or permitting pointers in Java ;-).

Also, your solution seems to be less expandable: suppose 
you decide to add different bgcolor attributes to rows depending 
on their contents, or to suppress a row if all its cells are empty... 
You can hardly place any XSLT operators inside CDATA section.

Anyhow, I hope people will agree there that breaking 
is not that hard to do in XSLT ;-)

>My solution requires a single pass over all the nodes and
>does not depend on walking lots of different axes or
>on a potentially very, very deep recursion loop.
>Think about the problem if the list of elements is 200,000 long!

I don't really see any problem: the stack depth required for
my solution is $max. I hope no one will group elements by
batches of 200,000. I didn't care about optimization; if you 
are concerned about template calling overhead, here's
the rewording of the same thing that does the grouping in 
a single template - two nested loops as in C/Perl. 

<xsl:template match="data">
  <table>
    <xsl:for-each select="field[position() mod $max = 1]" >
      <tr>
         <xsl:for-each select="self::field |
                      following-sibling::field[position() < $max]>
            <td><xsl:apply-templates/></td>
         </xsl:for-each>
      </tr>
    </xsl:for-each>
  </table>
</xsl:template>

Regards,
Nikolai


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


Current Thread