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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:16:30+00:00 2026-06-07T20:16:30+00:00

I have the following XML document: <?xml version=1.0 encoding=UTF-8?> <cars> <car body=Wagon> <text>Red</text> </car>

  • 0

I have the following XML document:

<?xml version="1.0" encoding="UTF-8"?>
<cars>
    <car body="Wagon">
        <text>Red</text>
    </car>
    <car body="Sedan">
        <text>Yellow</text>
    </car>
    <car body="Sedan">
        <text></text>
    </car>
    <car body="Wagon">
        <textlist>
            <text>Red</text>
            <text>Green</text>
            <text>Black</text>
            <text>Blue</text>
        </textlist>
    </car>
    <car body="Sedan">
        <textlist>
            <text>Yellow</text>
            <text>Orange</text>
        </textlist>
    </car>
    <car body="Fastback">
        <textlist>
            <text>Yellow</text>
            <text>Red</text>
            <text>Green</text>
            <text>Black</text>
            <text>Blue</text>
        </textlist>
    </car>
    <car body="Fastback">
        <textlist>
            <text>Pink</text>
            <text>Red</text>
            <text>Orange</text>
        </textlist>
    </car>
</cars>

Using XSLT 1.0 I need to transform the XML document to this format:

<?xml version="1.0" encoding="UTF-8"?>
<cars>
    <car type="Wagon">Red</car>
    <car type="Sedan">Yellow</car>
    <car type="Wagon">Green</car>
    <car type="Wagon">Black</car>
    <car type="Wagon">Blue</car>
    <car type="Sedan">Orange</car>
</cars>

Notice that:

  1. body=”Fastback” is excluded
  2. Duplicates are excluded (Red Wagon
    appears twice)
  3. Textlist multiple items are put as individual
    elements in the output XML
  4. Ignore empty values
  • 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-07T20:16:33+00:00Added an answer on June 7, 2026 at 8:16 pm

    Here is a sample:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:output indent="yes"/>
    
    <xsl:key name="k1" 
      match="car[not(@body = 'Fastback')]//text"
      use="concat(ancestor::car/@body, '|', .)"/>
    
    <xsl:template match="cars">
      <xsl:copy>
        <xsl:apply-templates select="car[not(@body =  'Fastback')]//text
          [generate-id() = generate-id(key('k1', concat(ancestor::car/@body, '|', .))[1])]"/>
      </xsl:copy>
    </xsl:template>
    
    <xsl:template match="text">
      <car type="{ancestor::car/@body}">
        <xsl:value-of select="."/>
      </car>
    </xsl:template>
    
    </xsl:stylesheet>
    

    It uses Muechian grouping, see http://www.jenitennison.com/xslt/grouping/muenchian.xml if you are not familiar with that XSLT 1.0 approach.

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

Sidebar

Related Questions

I have the following simple XML document: <?xml version=1.0 encoding=UTF-8?> <cars> <car> <data attrib=Make>
I have the following string loaded to an XML document: <?xml version='1.0' encoding='utf-8'?> <soapenv:Envelope
I have an xml document in the following format. <?xml version=1.0 encoding=UTF-8 ?> <Rows>
I have an loaded an XML document with the following structure: <?xml version=1.0 encoding=UTF-8
I have the following XML document <?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:issues='http://schemas.google.com/projecthosting/issues/2009' gd:etag='W/DEAERH47eCl7ImA9WhZTFEQ.'><id>http://code.google.com/feeds/issues/p/chromium/issues/full/921</id><published>2008-09-03T22:51:22.000Z</published><updated>2011-03-19T01:05:05.000Z</updated><title>Incorrect rendering</title><content
I have the following XML document : <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE inventory SYSTEM books.dtd>
Consider we have the following xml document <?xml version=1.0 encoding=utf-8?> <Root> <Child /> </Root>
I have the following XML document: <?xml version=1.0 encoding=UTF-8?> <Offices id=0 enabled=false> <office />
I have an xml document with the following structure: <?xml version=1.0 encoding=UTF-8?> <items> <item>
I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property

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.