xsl-list
[Top] [All Lists]

RE: Using vars

2004-07-27 06:00:55
Hi:

I keep forgeting that when i hit reply the msg does not go to the list, but to
the person that send the original msg...

I've sended a reply to Tom clarifying some of his points.

I can't test this beacause i'm just writing a "framework" that will be feed with
xml's not know to me at the time, i'm just working with a couple of examples.
So i don't know how big the tree can be.

But as Tom pointed, there is also the question of clarity and maintenence.

I've came up with this, folowing both your sugestions:

    <xsl:variable name='zoom-base'
select="/Formatos/Forms/Form/Grids/Grid/Zooms/Zoom[ModoZoom[contains(.,
'Z')]]"/>  --> it changes from the 'xxx'
    <xsl:variable name='pages'>
      <xsl:for-each select="$zoom-base"><xsl:value-of select="FormZoom"
/>:</xsl:for-each>
    </xsl:variable>
    <xsl:variable name='params'>
      <xsl:for-each select="$zoom-base"><xsl:value-of select="ParametroZoom"
/>:</xsl:for-each>
    </xsl:variable>

now i can use these vars in various places...

      <Event method="tablemouse" type="MouseHandler" target="GridPanel">
        <xsl:attribute name="next"><xsl:value-of select="$pages"
/></xsl:attribute>
        <xsl:attribute name="params"><xsl:value-of select="$params"
/></xsl:attribute>
      </Event>
      <xsl:for-each select="/Formatos/Forms/Form/Grids/Grid">
        <Event method="tablemouse" type="MouseHandler">
          <xsl:attribute name="target"><xsl:value-of select="@Nome"
/></xsl:attribute>
          <xsl:attribute name="next"><xsl:value-of select="$pages"
/></xsl:attribute>
          <xsl:attribute name="params"><xsl:value-of select="$params"
/></xsl:attribute>
        </Event>
        <Event method="tablemouse" type="MouseHandler">
          <xsl:attribute name="target"><xsl:value-of
select="concat('SPane_',@Nome)" /></xsl:attribute>
          <xsl:attribute name="next"><xsl:value-of select="$pages"
/></xsl:attribute>
          <xsl:attribute name="params"><xsl:value-of select="$params"
/></xsl:attribute>
        </Event>
      </xsl:for-each>
      <Event method="nextPage" target="btnProceed" type="ActionHandler">
        <xsl:attribute name="next"><xsl:value-of select="$pages"
/></xsl:attribute>
        <xsl:attribute name="params"><xsl:value-of select="$params"
/></xsl:attribute>
       </Event>


It seems clear and maintenable, but don't know about the performance. I guess i
just wait and see if the problem ever arises...


Thanks all.



Citando Michael Kay <mhk(_at_)mhk(_dot_)me(_dot_)uk>:

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[(_at_)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(_at_)sapo(_dot_)pt]
Sent: 26 July 2004 19:09
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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[(_at_)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[(_at_)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[(_at_)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.


--+------------------------------------------------------------------
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>
--+--









O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt


<Prev in Thread] Current Thread [Next in Thread>