[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Using vars


Subject: RE: [xsl] Using vars
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Mon, 26 Jul 2004 21:26:54 +0100

You can't ask questions about performance without saying what XSLT processor
you are using, and you can't reliably answer them except by measuring and
comparing.

My own approach would be to define one variable:

<xsl:variable name="pages"
  select="/Formatos/Forms/Form/Grids/Grid/Zooms/Zoom[@Coluna!='xxx']" />

and then do:

<xsl:for-each select="$pages/FormZoom">

<xsl:for-each select="$pages/ParametroZoom">

I've no idea how the performance will compare on any given processor, but
the code seems better structured that way.

Michael Kay



 

> -----Original Message-----
> From: xptm [mailto:xptm@xxxxxxx] 
> Sent: 26 July 2004 19:09
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Using vars
> 
> In terms of performance, what will be the best way to do 
> this?  Having:
> 
> <Formatos>
>   <Forms>
>     <Form Nome="ProcessoTipoGrupoListaDoc">
>       <Grids>
>         <Grid Nome="ProcessoTipoGrupoLista_Grid" 
> SourceObject="ProcessoTipoGrupoLista_Grid">
>           <Zooms>
>             <Zoom Coluna="ProcessoTipoGrupo">
>               <FormZoom>ProcessoTipoGrupoDoc</FormZoom>
>               <ModoZoom>AZ</ModoZoom>
>               <ParametroZoom>ProcessoTipoGrupo</ParametroZoom>
>             </Zoom>
>           </Zooms>
>         </Grid>
>       </Grids>
>       (*/ n Grids/ *)
>     </Form>
>   </Forms>
> </Formatos>
> 
> should i use one variable like
> 
> <xsl:template name="StandardEvents">
>   <Events>
>     <xsl:variable name="pages"
>       
> select="/Formatos/Forms/Form/Grids/Grid/Zooms/Zoom[@Coluna!='x
> xx']/*[name()='FormZoom' 
> or name()='ParametroZoom']" />
>     <Event method="tablemouse" type="MouseHandler">
>             <xsl:attribute name="target">GridPanel</xsl:attribute>
>             <xsl:attribute name="next">
>               <xsl:for-each select="$pages">
>                 <xsl:if test="name()='FormZoom'">
>                   <xsl:value-of select="." />
>                   <xsl:text>:</xsl:text>
>                 </xsl:if>
>               </xsl:for-each>
>             </xsl:attribute>
>             <xsl:attribute name="params">
>               <xsl:for-each select="$pages">
>                 <xsl:if test="name()='ParametroZoom'">
>                   <xsl:value-of select="." />
>                   <xsl:text>:</xsl:text>
>                 </xsl:if>
>               </xsl:for-each>
>             </xsl:attribute>
>     </Event>
>   </Events>
> </xsl:template>
> 
> 
> or two vars, like
> 
> <xsl:template name="StandardEvents">
>   <Events>
>      <xsl:variable name="pages">
>             <xsl:for-each 
> select="/Formatos/Forms/Form/Grids/Grid/Zooms/Zoom[@Coluna!='xxx']">
>               <xsl:value-of select="concat(ParametroZoom,':')" />
>             </xsl:for-each>
>      </xsl:variable>
>      <xsl:variable name="params">
>           <xsl:for-each 
> select="/Formatos/Forms/Form/Grids/Grid/Zooms/Zoom[@Coluna!='xxx']">
>             <xsl:value-of select="concat(ParametroZoom,':')" />
>           </xsl:for-each>
>      </xsl:variable>
>  
>      <Event method="tablemouse" type="MouseHandler">
>             <xsl:attribute name="target">GridPanel</xsl:attribute>
>             <xsl:attribute name="next">
>               <xsl:value-of select="$pages" />
>             </xsl:attribute>
>             <xsl:attribute name="params">
>               <xsl:value-of select="$params" />
>             </xsl:attribute>
>            </xsl:attribute>
>     </Event>
>   </Events>
> </xsl:template>
> 
> 
> If i understand correctly, the first only traverses the tree once and 
> the second two times, so if the tree is very big the first 
> option is better?
> 
> Thxs.


Current Thread
Keywords