This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: accessing previously created element


At 01:07 PM 5/1/2002, you wrote:
>unfortunately when transforming the i'th 'a' element to a 'b' (assume i > 
>1) I also need to access the (i-1)'th 'b' element; that is, the values 
>used to create a 'b' element are dependent upon the current 'a' element 
>being transformed and the preceding 'b' element.  Is this possible?  in a 
>single pass?

   Not making any claims about efficiency, it looks like you'll need to use 
recursion and hope that your XSLT engine creates each previous node only 
once and stores it somewhere internally.

<xsl:template name="b-from-a">
   <xsl:param name="local-a" />
   <xsl:choose>
     <xsl:when test="not($local-a)">
       <!-- Shouldn't be reached unless your initial call is bogus. -->
     </xsl:when>
     <xsl:when test="$local-a/preceding-sibling::a[1]">
       <xsl:variable name="prev-b">
         <xsl:call-template name="b-from-a">
           <xsl:with-param select="$local-a/preceding-sibling::a[1]" />
         </xsl:call-template>
       </xsl:variable>
       <!--
            Use $local-a and $prev-b to construct "b"
       -->
       <xsl:value-of select="..." />
     </xsl:when>
     <xsl:otherwise>
       <!--
            First occurrence (i == 1)
            Construct it however you normally do it.
       -->
       <xsl:value-of select="..." />
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>


Greg Faron
Integre Technical Publishing Co.



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]