Subject: Re: [xsl] Relationships in for-each statement From: "Bob Portnell" <simply.bobp@xxxxxxxxx> Date: Fri, 8 Sep 2006 09:55:08 -0700 |
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?
Bob Portnell simply.bobp@xxxxxxxxx
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Relationships in for-each, David Carlisle | Thread | Re: [xsl] Relationships in for-each, David Carlisle |
Re: [xsl] make recursive call, Mukul Gandhi | Date | [xsl] Sum in conjunction with strin, Steve |
Month |