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: Looping and assigning into variable


Hi Venkat,

> Actually I had to concatenate 2 child elements for each header and
> concatente result with previous one. So according to your suggestion
> I have to do like,
>
>   <Comments>
>     <xsl:for-each select="Header">
>       <xsl:value-of select="concat(RefNo,Comment)" />
>     </xsl:for-each>
>   </Comments>
>
> Is that correct?

Yes, that's correct.

> So Is it good way to apply template on same match, mutiple times in
> the same document as :
>
>    <xsl:for-each select="Header">
>       -- do some thing --
>    </xsl:for-each>
>
>    <Comments>
>         <xsl:for-each select="Header">
>             <xsl:value-of select="concat(RefNo,Comment)" />
>         </xsl:for-each>
>    </Comments>  

Yes, that's one way of doing it. Another way would be to use modes and
apply templates in one mode to generate the 'body', and one mode to
get the comments:

  <xsl:apply-templates select="Header" mode="body" />
  <Comments>
    <xsl:apply-templates select="Header" mode="comment" />
  </Comments>

Then have templates in the different modes for the different kinds of
processing of the same Header elements:
  
<xsl:template match="Header" mode="body">
  -- do something --
</xsl:template>

<xsl:template match="Header" mode="comment">
  <xsl:value-of select="concat(RefNo, Comment)" />
</xsl:template>

> I had the impression that XSLT processor parses input XML in SAX
> manner thus it matches an Element and applies relavant template only
> once. Am I wrong?

Yes, you're wrong. The XSLT processor reads in the entirety of an XML
document and stores it in a node tree, which is much like a DOM. You
can then process each node as many times as you like, in separate
xsl:for-eaches or in different modes to do different things. In the
XPaths in your stylesheet, you can jump back and forth in the node
tree to your heart's content.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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]