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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:22:13+00:00 2026-05-22T21:22:13+00:00

Sorry but a total xslt noob here Given XML that looks like: <Foo> <Bar

  • 0

Sorry but a total xslt noob here

Given XML that looks like:

<Foo>
  <Bar />
  <Baz />
  <Qax />
  <FooBar />
</Foo>

Is there an XSLT that will limit the number of child nodes under Foo so that there are only 3?

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

    This transformation uses and overrides the identity rule/template:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*" name="identity">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="/*/*[position() > 3]"/>
    </xsl:stylesheet>
    

    When applied on the provided XML document:

    <Foo>
        <Bar />
        <Baz />
        <Qax />
        <FooBar />
    </Foo>
    

    the wanted, correct result is produced:

    <Foo>
       <Bar/>
       <Baz/>
       <Qax/>
    </Foo>
    

    Explanation:

    1. The identity rule/template copies every node “as-is”.

    2. We have just one additional template that overrides the identity rule for any element that is a child of the top element with position greater than 3. This template dos nothing (has an empty body), which effectively prevents any such element from being copied to the output (or as we use to say, “deletes” it).

    Do note:

    1. Using and overriding the identity rule is the most fundamental and powerful XSLT design pattern.

    2. Using this design pattern is recommended over a simple <xsl:copy-of>, because it allows the nodes not only to be copied, but to be processed by any template we provide. Attributes of all elements are also processed.

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

Sidebar

Related Questions

first of all, sorry if that question is dumb but I´m a total newbie
Sorry if this is a total noob question, but I wanted to try to
Sorry about the vague subject but I couldn't think what to put. Here's my
Sorry for the simple question but I feel like there's a smarter way to
sorry for the noob question, but I'm new to C++. I need to read
Sorry if this is too obvious, but I am a total newcomer to lua,
Sorry for turning to here for such a basic question, but can someone just
I'm a total noob when it comes to jQuery but I am trying to
I have an XML schema that I need to extract values from but I
sorry if my question kind of doesn't make sense but i am total confused

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.