xsl-list
[Top] [All Lists]

Re: [xsl] Comparing an XML value from current record and previous record

2007-05-10 07:55:55
Hi Brett

"Looping through a recordset" is not something XSLT can do, as that implies that you can instruct XSLT to perform a loop, which you can't (notwithstanding the xsl:for-each, which is not a loop instruction, it selects a node-set and processes them, not necessarily in any order).

Your sample code is unparsable and I am not certain what to make of it. It helps to have a tiny working XML and XSLT sample that we can run to see exactly what you mean and help you get the output correct.

Of what I do understand of your code is that you use xsl:for-each in a way that it is not necessary (but not wrong either) to use it, but before you know it, you end up with lot's of nested for-each instructions which won't help the clarity and maintainability of your code. Instead, use matching templates and apply-templates where you now use xsl:for-each:

<!-- place this at your current for-each -->
<xsl:apply-templates select="RACE_LIST_HORSES/HORSE" />

<!-- place this somewhere in the root level of your stylesheet -->
<xsl:template match="HORSE">
  <section startonnewpage="false" .... etc
  ...
</xsl:template>

Now, to answer your question: right where you want this exception. You do not need an xsl:if instruction. Just use apply-templates again. Where you currently would place the xsl:if, place the following instruction:

<xsl:apply-templates select="HORSE_FRONT_ROW_FLAG[. = '2' and preceding-sibling::HORSE/HORSE_FRON_ROW_FLAG[. = '1']" />

<!-- and place this somewhere at the root level again -->
<xsl:template match="HORSE_FRONT_ROW_FLAG">
  your text here that otherwise would be in the if-instruction
</xsl:template>

If you find that the template is called to often because of other instructions that trigger it, you can give both the xsl:apply-templates and the xsl:template a mode of your choice (make sure they are the same).

HTH,
Cheers,
-- Abel Braaksma

Brett Luntz wrote:
Hi,
I am new to XSL and have some code that I need edited.

We are currently looping through an XML recordset.
We need an if statement that checks the current and
previous record's value of the XML tag
"HORSE_FRONT_ROW_FLAG".  If the current record's value
of HORSE_FRONT_ROW_FLAG tag is "2", and the previous
record's value of HORSE_FRONT_ROW_FLAG is "1", then
the system needs to print some text....
<snip />


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>