XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Neal WaltersSubject: Group Compare
Author: Neal Walters
Date: 28 Apr 2006 03:11 PM
In XSLT, I want to compare the entire group of an element.
For example, I have OriginalProfile and EditedProfile, and if anything is different between the two (such as home phone, work phone, cell phone, email, address, etc... I want to perform an action.

If I just do
<xslt:if test="OriginalProfile != EditedProfile")

I'm thinking it will just compare the text value of the group, not the values of everything under the group.

Is there an easy way to do what I'm asking? Or do I have to have a humungous if statement that compares oldWorkPhone to newWorkPhone, and oldCellPhone to NewCellPhone, etc...

Thanks,
Neal Walters
http://Biztalk-Training.com

Postnext
Ivan PedruzziSubject: Group Compare
Author: Ivan Pedruzzi
Date: 28 Apr 2006 03:38 PM
Hi Neal,

In XPath 1.0 the operator = between two node-sets is defined as

"
If both objects to be compared are node-sets, then the comparison will be true if and only if there is a node in the first node-set and a node in the second node-set such that the result of performing the comparison on the string-values of the two nodes is true.
"

When comparing two nodes only text nodes are considered so for instance comparing the following nodes return true even if they have a different child (name vs. newname)

<OriginalProfile>
<name>Ivan</name>
</OriginalProfile>

<EditedProfile>
<newname>Ivan</newname>
</EditedProfile>


Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
Neal WaltersSubject: Group Compare
Author: Neal Walters
Date: 03 May 2006 11:07 AM
So what is an elegant solution for this situation?

I have two profiles, a before and after. They have maybe 20 fields, name, addresses, city, state, zip, multiple phones, multiple emails, etc...

I basically want to know if the one profile is equal to the other or not.

Right now we have a map that has a nasty if statement that compares old first name to new first name, old last name to new last name, old address to new address, old city to new city, etc, etc, etc...

So, if we ever add an element to the structure, the if statement is out of date, and also the if statement is just extremely hard to read. When we click the format button in Stylus Studio, the whole if statement goes to one line, which is something like 2000 characters wide. I normally like the reformat button, but in this case it make the code very hard to read.

Any suggestions to improve my ugly XSLT?

Thanks,
Neal Walters
http://Biztalk-Training.com



Postnext
Ivan PedruzziSubject: Group Compare
Author: Ivan Pedruzzi
Date: 03 May 2006 03:10 PM
Neal,

I wrote a simple generic XSLT template called deep-diff that calculates the differences between two nodes, it should be sufficient to solve your problem. The template assumes that sub-elements are in the same position

Hope this helps
Ivan Pedruzzi
Stylus Studio Team


Documentdeep-equal.xsl

Postnext
Ivan PedruzziSubject: Group Compare
Author: Ivan Pedruzzi
Date: 03 May 2006 03:11 PM
... and the xml to test

Ivan Pedruzzi
Stylus Studio Team


Documentdeep-diff.xml

Postnext
Neal WaltersSubject: Group Compare
Author: Neal Walters
Date: 03 May 2006 06:17 PM
WOW! That's really cool. Did you have that in your bag of tricks already?

For now, I just need to know if they are the same or not.
The other day, I think I learned that it is impossible to return a variable from a called-template, is that true? Is there a nice get-around?

In other words, can I set a $same flag to true or false, and return it from the called template?

Thanks again,
Neal Walters
http://Biztalk-Training.com

Posttop
Ivan PedruzziSubject: Group Compare
Author: Ivan Pedruzzi
Date: 03 May 2006 07:26 PM
Nope you have capture the template result in a variable then check if it contains nodes

<xsl:variable name="compare">
<xsl:call-template name="deep-diff">
<xsl:with-param name="p1" select="books/book[1]" />
<xsl:with-param name="p2" select="books/book[2]" />
</xsl:call-template>
</xsl:variable>

<xsl:choose>
<xsl:when test="count(msxsl:node-set($compare)/*) > 0">
the nodes are different
</xsl:when>
<xsl:otherwise>the nodes are equal</xsl:otherwise>
</xsl:choose>


Hope this helps
Ivan Pedruzzi
Stylus Studio Team

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.