First post here!
Ok.. I have a contact XML as follows:
<contact>
<item>
<ContactData type="String">+4444444444</ContactData>
<Type type="String">1</Type>
</item>
<item>
<ContactData type="String">+9999999999</ContactData>
<Type type="String">3</Type>
</item>
<item>
<ContactData type="String">anyone123452154@gmail.com</ContactData>
<Type type="String">4</Type>
</item>
<item>
<ContactData type="String">+5554444444</ContactData>
<Type type="String">2</Type>
</item>
</contact>
As you can see type 4 is an e-mail, type 1 is a telephone number, type 2 is a fax and type 3 is a mobile number.
So here’s my scenario:
I (probably) need to iterate through all these nodes. Check to see if there is a telephone number (highest priority) and choose it. If there’s no telephone number we need to check for mobile number (second highest priority). If mobile number is not available we choose e-mail (or we do nothing). How can I achieve it?
Thanks..
One way to achieve this could be to simply iterate over the item elements with an xsl:for-each, with a sort on the value of the Type element. Then you can simply pick the first element.
Here is the full XSLT
When applied to your sample XML, the following is output
If you were to blank out the phone number, it should return the mobile number instead. Blank that out too, and the email address is returned.
EDIT: If you need to exclude the fax number, you could change the xsl:for-each to the following:
Or if you wanted to explicity state only phone, mobile or email, then you could do the following