[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Using vars

Subject: RE: Using vars
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Mon, 26 Jul 2004 14:55:44 -0400
for each xsl twice
> From: xptm [mailto:xptm@xxxxxxx]
> In terms of performance, what will be the best way to do this?
> <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

I would do neither (see below).

> <xsl:template name="StandardEvents">
>   <Events>
>     <xsl:variable name="pages"
> )='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
> [2nd example snipped]

First, you can simplify the basic template.  For example
/*[name()="xxx"] is the same as simply /xxx. For the fixed value
attributes, you do not need to use xsl:attribute, just use literal
result fragments.  You do not need the xsl:text elements, either.

Second, the design somewhat depends on whether you may sometimes have
more than "FormZoom" elements etc., in a "Zoom" element.  From your
design, it looks like you expect to have more than one, and to use the
":" to separate them.  If this is not the case, the template can be
simplified more.

Here is how I would probably do it -

<xsl:template name="StandardEvents">
  <xsl:variable name='zoom-base'

  <xsl:variable name='pages' select="$zoom-base/FormZoom"/>
  <xsl:variable name='parms' select="$zoom-base/ParametroZoom"/>
    <Event method="tablemouse" type="MouseHandler" target='GridPanel'
      <xsl:attribute name="next">
        <xsl:for-each select="$pages">
          <xsl:value-of select="." />:
      <xsl:attribute name="params">
        <xsl:for-each select="$parms">
          <xsl:value-of select="." />:

If there will never be more than one FormZoom, etc., element in a Zoom
element, then I would use this -

    <Event method="tablemouse" type="MouseHandler" target='GridPanel'
       Next='{$pages}:' params='{$parms}:'/>

As for which is faster, you always have to test.  If the processor has
to evaluate /*[name()="xxx"], that will be slower than telling it /xxx
directly.   OTOH, the processor might detect that the two are the same
and optimize away the difference.  Your second method does require a
long xpath expression to be evaluated twice, which is why I used the
working variable zoom-base above.  But you never know - perhaps some
processor could determine that the base part of the two xpath
expressions is the same and re-use it.

However, separating the two expressions into two cleanly written
variables makes the code easier to read and to maintain.  That's worth

If you only use xsl:element and xsl:attribute when you absolutely need
to, your code will also be easier to read and maintain.  The only reason
to use them is to insert calculated element or attribute names, sonly
use them for that purpose.

Current Thread
  • Using vars
    • xptm - Mon, 26 Jul 2004 19:09:24 +0100
      • <Possible follow-ups>
      • Passin, Tom - Mon, 26 Jul 2004 14:55:44 -0400 <=
      • xptm - Tue, 27 Jul 2004 14:00:55 +0100


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.