Comparing Values

David (archive)

Usenet Archive
Joined
Jan 7, 2000
Messages
927
Reaction score
0
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 Carlisle

Usenet Archive
Joined
Jan 5, 2000
Messages
609
Reaction score
0
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)?

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

however you don't want this

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).

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 (archive)

Usenet Archive
Joined
Jan 7, 2000
Messages
927
Reaction score
0
Thanks, that FAQ covers it very nicely. A much neater way of doing things.

David Carlisle said:
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)?

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

however you don't want this

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).

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,798
Members
249,594
Latest member
henrywalsh

Latest Threads

Top