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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:58:56+00:00 2026-05-26T21:58:56+00:00

Im looking for a XSLT (1.0) stylesheet. I have input similar to this: <?xml

  • 0

Im looking for a XSLT (1.0) stylesheet.
I have input similar to this:

<?xml version="1.0" encoding="ISO-8859-1"?>

<city country="USA">
Washington
</city> 

<city country="USA">
New York
</city> 

<city country="Germany">
Berlin
</city> 

<country size="big">
USA
</country>


<country size="small">
Germany
</country>

I want output like this:

Country USA 
Size: big
Cities: 
Washington
New York

Country Germany
Size: small
Cities:
Berlin

I am trying something like a nested for-each loop. But I dont know how to access the node when im inside the other node.

If this is a duplicate question I am sorry: the problem might be that I dont really know how to express my problem to find similar questions.

  • 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-26T21:58:56+00:00Added an answer on May 26, 2026 at 9:58 pm

    Nested loops are not necessary. The following stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="text"/>
        <xsl:strip-space elements="*"/>
        <xsl:template match="/">
            <xsl:apply-templates select="/*/country"/>
        </xsl:template>
        <xsl:template match="country">
            <xsl:text>Country </xsl:text> 
            <xsl:value-of select="."/>
            <xsl:text>&#xa;Size: </xsl:text>
            <xsl:value-of select="@size"/>
            <xsl:text>&#xa;Cities:&#xa;</xsl:text>
            <xsl:apply-templates select="../city[@country=current()/text()]"/>
            <xsl:text>&#xa;</xsl:text>
        </xsl:template>
        <xsl:template match="city">
            <xsl:apply-templates/>
            <xsl:text>&#xa;</xsl:text>
        </xsl:template>
    </xsl:stylesheet>
    

    Applied to this input:

    <root>
        <city country="USA">Washington</city>
        <city country="USA">New York</city>
        <city country="Germany">Berlin</city>
        <country size="big">USA</country>
        <country size="small">Germany</country>
    </root>
    

    Produces:

    Country USA
    Size: big
    Cities:
    Washington
    New York
    
    Country Germany
    Size: small
    Cities:
    Berlin
    

    Note: The input you provided includes a lot of significant whitespace, which I removed in my example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following XSLT script: <?xml version=1.0 encoding=ISO-8859-1?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:output method=text encoding=iso-8859-1/>
Hello i have an XSLT that looks like so: <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:output omit-xml-declaration=yes
I'm looking for an xslt that does the following: With the input xml of,
I am looking to merge multiple xslt stylesheets (V1.0) into one stylesheet. I have
I am looking to sort an XML structure using XSLT using xsltproc: The xml
Looking to do a bit of refactoring... Using NHibernate I have this query currently
Looking for best advice on how to do this: I have an insert like
In this case I have XML data source and external images files whole together
Looking to use XSLT to transform my XML. The sample XML is as follows:
I have a directory of very large XML files with a structure as this:

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.