xsl-list
[Top] [All Lists]

Re: [xsl] Relationships in for-each statement

2006-09-08 09:55:31
Yay! It works, once I put in the third characteristic to re-establish
context. :-)

Can I prevail upon one more, bonerattlingly easy, question? The
structure is now...

<xsl:for-each select="key('findTitle', lower-case($matcher), $tvd)/@id">
   <xsl:if test="*[1][parent::tv:program]">
       <xsl:call-template name="topicTop" >
           <xsl:with-param name="topic" select="$matcher" />
       </xsl:call-template>
   </xsl:if>
   <xsl:call-template name="makeReport" >
       <xsl:with-param name="ProgramID" select="." />
    </xsl:call-template>
</xsl:for-each>

That <xsl:if> means to test whether or not this is our first pass
through the loop, and if it is, print the pretty topic line associated
with our successful match. My test condition is botched, though. I've
found many which won't print the header, and I've found one which will
print for every item in the set. I know I need to break myself of
thinking in terms of "iterations," 'cause that's not what's actually
going on. Would I be better off just keeping that test ahead of the
loop?

Just think, the weekend's almost here and we'll be done with me nattering on!

Bob Portnell
simply(_dot_)bobp(_at_)gmail(_dot_)com

On 9/8/06, David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk> wrote:

  Well, trying this, I find a problem in that my expression

  <xsl:for-each select="//program[tv:title = $matcher]/@id">

  isn't really in that form.


<xsl:for-each select="//program[tv:title = $matcher]/@id">

is

<xsl:key name="x" match="program" use="tv:title"/>

...
<xsl:for-each select="key('x',$matcher)/@xid">


but as I say if you only have //program[tv:title=something] once in the
stylesheet then you have to take the hit of searching the document at
least once so a key may not help(I just say this so implementors of
smart optimisers can jump in and say that they make this a false
statement:-) the key only wins if you do the search more than once. it
wins big time and can make orders of magnitute speedup if you are doing
this

<xsl:for-each select="//program[tv:title =
$matcher][following-sibling::program[tv:title=something]]/@id">

as then changing to a key can change an n-squared algroithm to an n or
less) algorithm and if you've a 100 programs 10000 is a lot less than
100:-) This is why "muenchian grouping" (ie using keys for grouping
problems made such a big impact on xslt 1 usage, as typically not only
did you have to seach down to find all the items you searched across (or
down again, which is worse) to find all the ones in the same group.

David



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