xsl-list
[Top] [All Lists]

Re: [xsl] Slow XSLT

2008-03-12 20:20:35
Hi David,

Many thanks for your reply.

Sorry, I should have included you in my previous post
to Michael but there you go again. Is this explanation
clearer?

For each Row in my xml I need to output a <tr>. So I
apply templates. 

<xsl:variable name=set" select="Report/Rows//Row" />
.....
 <xsl:apply-templates select="$set"/>
.....

For each Cell within the current Row that is in the
node set I need to apply the Cell template to output
the necessary <td>s

<xsl:template name="Row">
......
<tr>
 <xsl:param name="set"/>
  <xsl:apply-templates select="$set[postion()]/*"/>
</tr>
<xsl:template>

<xsl:template name="Cell">
  When test Msr
   for each Msr
   <td> 
     <xsl:value-of select="@val" />
   </td>
  Otherwise
   For each Measure
    <td>&nbsp;</td>
<xsl:template>

However, if I do this - <xsl:apply-templates
select="$set/*"/> - I will apply templates to all the
Cell elements regardeless of the Row they belong to.
So I will have only one <tr> with lots of <td>s.
Something like that:

<tr>
<td></td> 
<td></td> 
<td></td> 
<td></td> 
<td></td> 
<td></td> 
<td></td> 
<td></td> 
</tr>

However, the output I need according to my xml below
is this:

<tr>
 <td>10</td> 
 <td>15</td> 
 <td>&nbsp;</td> 
 <td>&nbsp;</td>
</tr>
<tr> 
 <td>&nbsp;</td> 
 <td>&nbsp;</td>
 <td>45</td> 
 <td>34</td>
 <td>123</td> 
 <td>19</td> 
</tr> 

XML

<Report xmlns="">
  <Measures>
    <Measure idx="1" heading="Total Pages" />
    <Measure idx="2" heading="Cost" />
  </Measures>
  <Rows>
   <RowGrp>
    <Row heading="Name 1">
      <Cell>
        <Msr idx="1" val="10" />
        <Msr idx="2" val="15" />
      </Cell>
      <Cell/>
    <Row heading="Name 2">
      <Cell />
      <Cell>
        <Msr idx="1" val="45" />
        <Msr idx="2" val="34" />
      <Cell/>
      <Cell>
        <Msr idx="1" val="123" />
        <Msr idx="2" val="19" />
      <Cell/>
    </Row>
   </RowGrp>
  </Rows>
</Report>





--- David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk> wrote:



<xsl:apply-templates select="$set[postion()]/*"/>

a numeric filter such as $set[1] is shorthand for
the boolean filter
$set[position()=1]
so the above is shorthand fr
<xsl:apply-templates
select="$set[postion()=position()]/*"/>
so as the test is always true it is the same as
<xsl:apply-templates select="$set/*"/>


I need to apply templates to the child of the
current
Row element that is in the $set node set. But the
'.'
xslt 1 doesn't have a direct test on node identity
you can howerver
use, for example

select="*[count(.|$set)=count($set)]"

which selects all child elements that are in the set
$set.


This XPATH works though:

<xsl:apply-templates select="./Cell"/>
 ./ at the start of an xpath is redundent, so this
is the same as

<xsl:apply-templates select="Cell"/>

and selects child Cell elements


How do I get the current context using a node set
variable?

You'd need to be clearer about what you mean here.
. or current() will get the current context

perhaps 

select="Cell[count(.|$set)=count($set)]"

is what you need but I can't be sure from this
description


I have created a node set of Rows:

<xsl:variable name=set" select="Report/Rows//Row"
/> 

you probably don't want // there which causes a
search to arbitrary
depth looking for Row elements, but why do you need
this variable 
at all, rather than simply applying templates to the
Row elements as
they occur in the source?

It would seem that by 


<xsl:template name="Row">
<tr>
 <xsl:param name="set"/>
 <xsl:apply-templates select="$set[postion()]/*"/>
</tr>
<xsl:template>



you want to select the children of _this_ Row, but
you don't need to do
anything for that, just



<xsl:template name="Row">
<tr>
 <xsl:apply-templates/>
</tr>
<xsl:template>

would work fine wouldn't it?

David


________________________________________________________________________
The Numerical Algorithms Group Ltd is a company
registered in England
and Wales with company number 1249803. The
registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR,
United Kingdom.

This e-mail has been scanned for all viruses by
Star. The service is
powered by MessageLabs. 

________________________________________________________________________


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





      ___________________________________________________________ 
Rise to the challenge for Sport Relief with Yahoo! For Good  

http://uk.promotions.yahoo.com/forgood/

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

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