View Single Post
  #4 (permalink)  
Old August 1st, 2007, 10:49 AM
mhkay's Avatar
mhkay mhkay is offline
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

>right now, the code will print <HTML> tag everytime //DATA contains somethings

Actually, it will output one <HTML> element for every LINE element in your source document. That's what xsl:for-each does.

>how can i set a condition or set variable to make a comparison between previous DATA content with current DATA content?

You can compare a node with its immediately preceding sibling using

<xsl:if test=". = preceding-sibling::*[1][self::DATA]">

or with all preceding siblings using

<xsl:if test=". = preceding-sibling::DATA">

For grouping in XSLT 2.0, use xsl:for-each-group. If you're stuck with 1.0, it's much more difficult, read about it at

But I'd suggest learning the basics first. Your first question suggests you haven't understood things like for-each, template rules, the meaning of "//", etc; don't try any fancy grouping until you've mastered these foundations.

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference