473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Comparing Values

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
Jul 20 '05 #1
2 1862

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

Jul 20 '05 #2
Thanks, that FAQ covers it very nicely. A much neater way of doing things.

David Carlisle <da****@nag.co.uk> wrote in message news:<yg*************@penguin.nag.co.uk>...
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

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Elijah Bailey | last post by:
I have two char arrays of size k. I want to know which one is bigger (exactly like for instance I compare two ints/longs/etc.). What is the fastest way to do this? k <= 10 usually for my...
2
by: Manny Chohan | last post by:
Hi, i have two datetime values in format 11/22/04 9:00 AM and 11/22/04 9:30 AM. How can i compare dates .net c# or if there is any other way such as Javascript. Thanks Manny
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
5
by: Kermit Piper | last post by:
Hello, I am comparing two date values, one from a database and one that has been converted from a hard-coded string into an actual Date type. So far so good. The problem I'm having is that one...
2
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.