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 1020107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:06:58+00:00 2026-05-16T11:06:58+00:00

I am using XSLT to generate my HTML. I am having below xml and

  • 0

I am using XSLT to generate my HTML.

I am having below xml and I want to write condition if there is only one city node inside a country node I want to write some condition, please see the below xml.

There are two xmls.

1) destinations.xml

    <?xml version="1.0"?>
    <list type="Destinations">
    <resources location="include/xml/locations.xml">
    <publication>232</publication>
    </resources>
    <destination id="594904" title="Maldives" url="/destinations_offers/destinations/asiapacific/maldives/maldives.aspx" thumbnail="/99/english/images/square_tcm481-594879.jpg" FeaturedDestination="true">        
    <city id="192513" />
    </destination>
    <destination id="594089" title="New Delhi" url="/destinations_offers/destinations/asiapacific/india/newdelhi.aspx" thumbnail="/99/english/images/sydney_tcm481-594346.jpg" FeaturedDestination="true" NewestDestination="true">        
    <city id="192460" />
    </destination>
    </list>

For eample In the above xml there is city id = 192513 for maldives and it is alone node in locations.xml this will be checked in below locations.xml and if that id is alone in that country node then I need to call specific condition.

<?xml version="1.0"?>
<list type="Locations">
<region id="192393" code="ASIA" name="Asia &amp; the Pacific" shortname="Asia &amp; the Pacific">
<country id="192395" code="AU" name="Australia" shortname="Australia">
<city id="192397" code="BNE" name="Brisbane" shortname="Brisbane">
<airport id="192399" code="BNE" name="Brisbane International Airport" shortname="Brisbane"></airport>
</city>
<city id="192409" code="SYD" name="Sydney" shortname="Sydney">
<airport id="192411" code="SYD" name="Kingsford Smith Airport" shortname="Sydney"></airport>
</city>
</country>
<country id="192511" code="MV" name="Maldives" shortname="Maldives">
<city id="192513" code="MLE" name="Male" shortname="Male">
<airport id="192515" code="MLE" name="Male International Airport" shortname="Male"></airport>
</city>
</country>
</region>
</list>

Please suggest!

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-05-16T11:06:58+00:00Added an answer on May 16, 2026 at 11:06 am

    Use:

    count($vLocations/*/*/country[city[@id = $vDestCity/@id]]/city) = 1
    

    In this expression $vLocations is the XML document with top element <list type="Locations"> and $vDestCity is the <city> element we are interested in from the XML document with top element <list type="Destinations">

    To see this in action:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:my="my:my">
     <xsl:output method="text"/>
    
     <my:locations>
        <list type="Locations">
            <region id="192393" code="ASIA" 
                    name="Asia &amp; the Pacific" 
                    shortname="Asia &amp; the Pacific">
                <country id="192395" code="AU" name="Australia"
                                   shortname="Australia">
                    <city id="192397" code="BNE" name="Brisbane"
                                       shortname="Brisbane">
                        <airport id="192399" code="BNE"
                                              name="Brisbane International Airport"
                                              shortname="Brisbane">
                                            </airport>
                    </city>
                    <city id="192409" code="SYD" name="Sydney" 
                                       shortname="Sydney">
                        <airport id="192411" code="SYD"
                                             name="Kingsford Smith Airport"
                                             shortname="Sydney">
                                            </airport>
                    </city>
                </country>
                <country id="192511" code="MV" name="Maldives"
                                    shortname="Maldives">
                    <city id="192513" code="MLE" name="Male"
                                         shortname="Male">
                        <airport id="192515" code="MLE" 
                                              name="Male International Airport"
                                              shortname="Male">
                                            </airport>
                    </city>
                </country>
            </region>
        </list>
     </my:locations>
    
     <xsl:variable name="vLocations"
      select="document('')/*/my:locations"/>
    
     <xsl:variable name="vDestCity1"
        select="/*/destination/city[@id=192513]"/>
    
     <xsl:variable name="vDestCity2"
        select="/*/destination/city[@id=192397]"/>
    
     <xsl:template match="/">
       <xsl:value-of select=
        "count($vLocations/*/*/country
                    [city[@id = $vDestCity1/@id]]/city
               ) = 1
        "/>
        :
    <xsl:text/>
       <xsl:value-of select=
        "count($vLocations/*/*/country
                    [city[@id = $vDestCity2/@id]]/city
               ) = 1
        "/>
    
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the provided destinations.xml:

    <list type="Destinations">
        <resources location="include/xml/locations.xml">
            <publication>232</publication>
        </resources>
        <destination id="594904" title="Maldives" url="/destinations_offers/destinations/asiapacific/maldives/maldives.aspx" thumbnail="/99/english/images/square_tcm481-594879.jpg" FeaturedDestination="true">
            <city id="192513" />
        </destination>
        <destination id="594089" title="New Delhi" url="/destinations_offers/destinations/asiapacific/india/newdelhi.aspx" thumbnail="/99/english/images/sydney_tcm481-594346.jpg" FeaturedDestination="true" NewestDestination="true">
            <city id="192460" />
        </destination>
    </list>
    

    The wanted, correct result is produced:

    true
        :
    false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code to transform XML to HTML using XSLT template: string uri
I'm using XSLT and need to generate the doctype dynamically in the transformed output,
I'm trying to move a Sharepoint Subsite into another one using the stsadm export
I want to provide user facility to change the CSS. First think clicked is
I have an XML document that have additonal nodes in it at different levels
using SQL server 2005+ for over a year now, I've been running a query
I have an XSLT file so as to transform large amount of data. I
I am using Umbraco and I need to display an image in a Rss
Is there anyway in a BizTalk map to force destination elements to be created
I host two sites in a single sitecore environment. I've modified web.config so that

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.