Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8437687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:30:11+00:00 2026-06-10T07:30:11+00:00

First post here! Ok.. I have a contact XML as follows: <contact> <item> <ContactData

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:30:13+00:00Added an answer on June 10, 2026 at 7:30 am

    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

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="text" indent="yes"/>
    
       <xsl:template match="contact">
          <xsl:for-each select="item[ContactData != '']">
             <xsl:sort select="Type" order="ascending" />
             <xsl:if test="position() = 1">
                <xsl:value-of select="ContactData" />
             </xsl:if>
          </xsl:for-each>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your sample XML, the following is output

    +4444444444
    

    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:

    <xsl:for-each select="item[Type != '2'][ContactData != '']">
    

    Or if you wanted to explicity state only phone, mobile or email, then you could do the following

    <xsl:for-each select="item[Type = '1' or Type = '3' or Type = '4'][ContactData != '']">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My first post here :) I have a summer job doing a bit of
This is my first post here. I have a problem. I need to take
first thread i post here. I have been searching here for answers and almost
Hello all this is my first post here i have been working in an
This is my first post here. I have been reading posts here since I
It is my first post here. I would have two questions with regard to
First post here, I have tried searching but couldn't find what I'm looking for
Well, this is my first post here and really enjoying the site. I have
First post here and it's and awk question. I have a file that looks
This is my first post here so kindly pardon any mistakes that I have.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.