Comparing Values

Discussion in 'XML' started by David, Jul 21, 2004.

  1. David

    David Guest

    Hi,

    I'm new to XML and XSLT in particular so if this is a stupid question
    then I apologise.

    I have an XML file which contains a number of occurrences of a
    specific element for example

    <test>Value1</test>
    <test>Value2</test>
    etc

    Is it possible using XSLT to compare whether an element is the same as
    the previous element of the same name (does that make any kind of
    sense, what I mean is the first <test> value the same as the next
    <test> value, which in the example above would not be the case)?

    I'm trying to create a template match which only occurs when the
    current occurrence of the node is the same as the previous occurrence
    of the node. It's basically so that in the output HTML I can keep the
    current table open when the two values match and close it when they
    change (to correct some table nesting issues that I seem to have run
    up against).

    I can only manage it at the moment when I know what the possible
    values are in advance which means it isn't much use (the value could
    be any combination of up to 6 characters so thats a whole lot of
    possible combinations to check for).

    Any assistance would be greatly appreciated, or even just to know
    whether it's possible or not.

    Thanks
     
    David, Jul 21, 2004
    #1
    1. Advertisements

  2. yes that would be
    <xsl:if test=".=preceding::test[1]"> ....

    however you don't want this

    Not the XSLT way of thinking of things, you can't "close a table" in some
    template on some condition as you are not writing tags such as
    "</table>" but creatinga node tree, so you first generate a table node
    then populate it with the elements you want, so you need to decide what
    they are up front by selecting each group of elements that should end up
    in the same table.

    This grouping problem isa faq and best answered at Jeni's site

    www.jenitennison.com/xslt/grouping

    David
     
    David Carlisle, Jul 21, 2004
    #2
    1. Advertisements

  3. David

    David Guest

    Thanks, that FAQ covers it very nicely. A much neater way of doing things.

     
    David, Jul 22, 2004
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.