XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] xsl processing problem with multiple templates

At 2009-11-14 20:40 -0500, Ian S. Worthington wrote:
>I decided to go with the pull model
>as, rightly or wrongly, I felt slightly more in control.

No criticism there ... a matter of style and future flexibility.  But 
I think you need the flexibility now that you are adding the 
hyperlink to your report.  You didn't have that in your earlier 
rendering of a fix.

>I ditched the inline
>data so I could generate a link to the full data contents for each fix. But I
>couldn't find a way of doing that *under* the for-each whilst still retaining
>access to the @href.

Using a variable would do that.

>So I ended up with the following which, whilst it works,
>is presumably reading the linked document twice just to extract the fix number
>and fix abstract:

In syntax, yes, in runtime, no ... a processor will keep the tree 
cached in memory so there is in fact no repeated load of the source tree.

>         <ul>
>           <xsl:for-each select="fix">
>             <!-- <xsl:for-each select="document( fix/@href )/fix"> -->
>             <li>
>               <a>
>                 <xsl:attribute name="href">
>                   <xsl:value-of select="@href"/>
>                 </xsl:attribute>
>                 <xsl:value-of select="document( @href )/fix/number"/>
>               </a>
>               <br/><xsl:value-of select="document( @href )/fix/abstract"/>
>             </li>
>           </xsl:for-each>
>         </ul>
>
>I'm sure there's a more efficient way, yes?

First let me show you how the above would take advantage of a 
variable, but the above and this won't handle the embedded fixes, 
only the referred fixes:

         <ul>
           <xsl:for-each select="fix">
             <xsl:variable name="link" select="@href"/>
             <xsl:for-each select="document( $link )/fix"> -->
               <li>
                 <a href="{$link}">
                   <xsl:value-of select="number"/>
                 </a>
                 <br/><xsl:value-of select="abstract"/>
               </li>
             </xsl:for-each>
           </xsl:for-each>
         </ul>

But from your earlier post you wanted to handle both embedded and 
referred fixes ... so you want two behaviours based on a fix and you 
want the handling in the order of the fixes, which is arbitrary.  The 
two behaviours are to hyperlink fixes that are referred, and to not 
hyperlink fixes that are embedded.

I'm going to suggest again the push method as follows, because it 
fits well with the processing of the mixture of types of fixes:

         <ul>
           <xsl:apply-templates select="fix"/>
         </ul>
       </body>
     </html>
   </xsl:template>

   <!--embedded-->
   <xsl:template match="fix">
      <li>
         <xsl:value-of select="number"/>
         <br/><xsl:value-of select="abstract"/>
      </li>
   </xsl:template>

   <!--referred-->
   <xsl:template match="fix[@href]">
     <xsl:variable name="link" select="@href"/>
     <xsl:for-each select="document( $link )/fix"> -->
       <li>
         <a href="{$link}">
           <xsl:value-of select="number"/>
         </a>
         <br/><xsl:value-of select="abstract"/>
       </li>
     </xsl:for-each>
   </xsl:template>

With the above you can now have any arbitrary order of embedded and 
linked fixes and they will be processed accordingly each to their 
needs.  This is a primary benefit of the push model:  handling 
arbitrary orders of nodes.  Mixed content is another example of where 
the push model shines, but for the same reason:  handling arbitrary 
orders of nodes.

I hope this helps.

. . . . . . . . . . . . Ken

--
Vote for your XML training:   http://www.CraneSoftwrights.com/x/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/x/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@CraneSoftwrights.com
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/x/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS