xsl-list
[Top] [All Lists]

Re: AW: recursion with xsl:apply-templates

2003-08-28 08:03:00
Tried that already, but it gives an error within xalan. I'll try again after upgrading to the most recent version.

Andrew Welch wrote:
<xsl:copy-of select="xalan:nodeset($indexToIDs)/entry[(_at_)genid =


Just one further thing...  I would suggest converting to a nodeset
outside of the iteration, so that it only gets performed once rather
than once per interation.

So if you have a global variable holding information that you will
query, add another variable beneath it that holds it as a nodeset, just
like:

<xsl:variable name="indexToIDs-rtf">
   <xsl:for-each select="/transformation/IRF//*[(_at_)index]">
     <xsl:variable name="pos" select="position()"/>
     <entry genid="{generate-id()}">
       <xsl:copy-of select="/transformation/id_list/id[$pos]"/>
     </entry>
   </xsl:for-each>
</xsl:variable>
<xsl:variable name="indexToIDs" select="exsl:node-set($indexToIDs)"/>

..and then reference the nodeset each time (notice the name changes).  I
don't know the figures but I would guess converting to a node-set is
more than just setting a boolean in the processor, so it's best done
once only (maybe someone knows).

cheers
andrew



Sorry David, obviously I did get you wrong then.

Anyway, I have a working and (thanks to Andrew) a performing solution
for my problem now, which is only slightly different from Andrews,

i.e.

I need the ids as element, not as attribute.

Thanks again for your support and contributions!
Volker.

My solution:

<xsl:variable name="indexToIDs">
    <xsl:for-each select="/transformation/IRF//*[(_at_)index]">
      <xsl:variable name="pos" select="position()"/>
      <entry genid="{generate-id()}">
        <xsl:copy-of select="/transformation/id_list/id[$pos]"/>
      </entry>
    </xsl:for-each>
  </xsl:variable>
  <xsl:template match="/transformation">
    <xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="*[(_at_)index]">
    <xsl:variable name="genid" select="generate-id()"/>
    <xsl:value-of select="$genid"/>
    <xsl:copy>
      <xsl:copy-of select="xalan:nodeset($indexToIDs)/entry[(_at_)genid =
$genid]/id"/>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="@index"/>
  <xsl:template match="id_list"/>


David Carlisle wrote:


it is like David assumed:


But your posted solution didn't do what mine did.
Mine took the value of the index attribute as the id element to copy
your solution ignored the value and counted the number of elements

that

had that attribute.

David



________________________________________________________________________

This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a

proactive

anti-virus service working around the clock, around the globe,

visit:

http://www.star.net.uk


________________________________________________________________________

XSL-List info and archive:

http://www.mulberrytech.com/xsl/xsl-list


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






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


--
Mit freundlichen Grüßen / With kind regards
Volker Witzel
____________________________________________
IBM Business Consulting Services
Karl-Arnold-Platz 1a, D-40474 Düsseldorf
fon (0211) 476-1924 (intern *129-1924)
mobil 0172-73 66 586
mail vwitzel(_at_)de(_dot_)ibm(_dot_)com


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