|
next
|
Subject: Simplifying this long if statement (Part 2) Author: Neal Walters Date: 19 May 2006 10:55 AM
|
Recently I asked for some help regarding a long if statement, and Ivan sent me a "Deep Diff Compare" callable template (which I will use), but I still have some long nasty if statements that are comparing just a few of the variables, not all of them.
It looks something like this:
<xsl:if test="(//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='Address1'] != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='Address1']) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='Address2'] != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='Address2']) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='Address3'] != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='Address3']) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='Address4'] != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='Address4']) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='City'] != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='City']) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='CountryDivision'] != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='CountryDivision']) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='Country'] != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='Country']) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='PostalCode'] != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='PostalCode']) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='HomePhone'] != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='HomePhone']) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='HomePhone']/@Preferred != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='HomePhone']/@Preferred) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='WorkPhone'] != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='WorkPhone']) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='WorkPhone']/@Preferred != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='WorkPhone']/@Preferred) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='WorkPhone']/@Extension != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='WorkPhone']/@Extension) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='CellPhone'] != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='CellPhone']) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='CellPhone']/@Preferred != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='CellPhone']/@Preferred) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='PreferredEmail'] != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='PreferredEmail']) or (//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='PreferredEmail']/@EmailType != //*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='PreferredEmail']/@EmailType) or not(//*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='PreferredEmail']) or not(//*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='HomePhone']) or not(//*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='WorkPhone']) or not(//*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='CellPhone']) ">
In English it is basically saysing - Is the old address = to the new address, and is the old homephone = to the new homephone and...etc...
There are two profiles, an OriginalProfile and an Profile (with the updates in it). Both contain the same elements.
When you press the format button in Stylus Studio, all this code goes to oneline. So it would really be cool if the formatter could honor line breaks, and maybe just handle the indention.
I'm debating if I should try to simplify this line. The problem is that you have to scroll almost 3900 characters back and forth to be able to read it, which to me is next to impossible.
Should I just create a bunch of vars like this, and then use the vars in the if statement?
<xsl:variable name="vUpdAddress1">
<xsl:value-of select="//*[local-name()='ProfileUpdateRequest']/*[local-name()='Profile']/*[local-name()='Address1']"/>
</xsl:variable>
<xsl:variable name="vOrigAddress1">
<xsl:value-of select="//*[local-name()='OriginalProfile']/*[local-name()='Profile']/*[local-name()='Address1']"/>
</xsl:variable>
Or I suppose I could right another callable-template where you pass it a list of variables to compare?
Any other ideas how to cut this if statement down to size?
I've actually considering just calling c# to do this transform.
Thanks,
Neal Walters
http://Biztalk-Training.com - Learn Biztalk Faster
http://Sharepoint-Training.com - End User Intro to Sharepoint (Videos)
|
|
|