xsl-list
[Top] [All Lists]

Re: Extracting the grouping from a flat structure

2004-12-07 17:52:48
Kev --

Wow. That's quite a solution. I did not know about the node-set function, which is available in xalan as 'xalan:nodeset'. When you had described the two-pass solution, I was thinking about piping two XSL transforms together (i.e., two separate stylesheets processed one after the other). I did not know that you could put trees into a variable and process them with node-set. That's very cool.

I implemented your solution, and it is a little bit faster. But only about 7% faster, unfortunately. On a sample XML file, it takes around 3000ms on average using my old method, and about 2800ms on average using your solution.

I guess I'm a little surprised that the performance gain isn't more, but maybe you're not. Any ideas for making it more efficient?

Thanks again for all your help.

Peter

On Dec 7, 2004, at 4:42 AM, Kevin Jones wrote:

On Monday 06 December 2004 22:52, Peter Wyngaard wrote:
Hi Kev --

Thanks for your reply.  Could you post sample code for
your two-pass idea?  I'm really new at XSL and I don't
think I follow your idea.

Sure, it is rather longer than your original but it might
help. I have used the non-standard node-set() function in
here, if you are not familiar with this have a read of
http://www.xml.com/pub/a/2003/07/16/nodeset.html. I have
also not tried to reproduce your exact formatting just the
general structure you needed.

Kev

<xsl:template match='table'>
 <xsl:variable name="postable">
  <index>
   <xsl:for-each select="tr">
    <xsl:if test="th">
     <pos><xsl:value-of select="position()"/></pos>
    </xsl:if>
   </xsl:for-each>
  </index>
 </xsl:variable>

 <xsl:call-template name="genxml">
  <xsl:with-param name="pos"
        select="node-set($postable)/index/pos"/>
  <xsl:with-param name="nodes" select="tr"/>
 </xsl:call-template>
</xsl:template>

<xsl:template name="genxml">
 <xsl:param name="pos"/>
 <xsl:param name="nodes"/>

 <xsl:choose>
  <xsl:when test="count($pos)=0"/>
  <xsl:when test="count($pos)=1">
   <header>
    <xsl:copy-of select="$nodes[position()=number($pos)]"/>
    <xsl:for-each select="$nodes[position()>number($pos)]">
     <row><xsl:copy-of select="."/></row>
    </xsl:for-each>
   </header>
  </xsl:when>
  <xsl:otherwise>
  <header>
   <xsl:copy-of select="$nodes[position()=number($pos)]"/>
   <xsl:for-each select="$nodes[position()>number($pos[1])
           and position()&lt;number($pos[2])]">
    <row>
     <xsl:copy-of select="."/>
    </row>
   </xsl:for-each>
  </header>
  <xsl:call-template name="genxml">
   <xsl:with-param name="pos" select="$pos[position()>1]"/>
   <xsl:with-param name="nodes" select="$nodes"/>
  </xsl:call-template>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--