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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:55:03+00:00 2026-05-21T11:55:03+00:00

I have this XML file: <Elements> <Element name=A.B.C.x> <Child>…</Child> <Child>…</Child> <Child>…</Child> </Element> <Element name=A.B.C.y>

  • 0

I have this XML file:

<Elements>
  <Element name="A.B.C.x">
    <Child>...</Child>
    <Child>...</Child>
    <Child>...</Child>
  </Element>
  <Element name="A.B.C.y">
    <Child>...</Child>
    <Child>...</Child>
  </Element>
  <Element name="A.D.E.y">
    <Child>...</Child>
  </Element>
  <Element name="A.D.E.z">
    <Child>...</Child>
    <Child>...</Child>
    <Child>...</Child>
  </Element>
</Elements>

I need to create XSL to get this result:

<Elements>
  <Element name="A.B.C">
    <LastToken name="x" childCount="3" />
    <LastToken name="y" childCount="2" />
  </Element>
  <Element name="A.D.E">
    <LastToken name="y" childCount="1" />
    <LastToken name="z" childCount="3" />
  </Element>
</Elements>

I am limited to XSL 1.0 with no extensions and I cannot figure out how to achieve the result.

Any help appreciated.
Thanks in advance.

EDIT: As some answers came in I saw I have to clarify my question/task:
Tokens in name attribute of Element node are not limited to one character. Sample value of ‘name’ attribute could be This.Is.Grouping.Target.AndThisIsGroupChild

  • 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-21T11:55:04+00:00Added an answer on May 21, 2026 at 11:55 am

    Just for fun, a general XSLT 1.0 solution without extensions:

    <!DOCTYPE xsl:stylesheet [
      <!ENTITY key "
    substring(
       @name,
       1,
       string-length(
          @name
       )
     - count(
          document('')//node()[
             not(
                contains(
                   substring(
                      current()/@name,
                      string-length(
                         current()/@name
                      )
                    - position()
                    + 1
                   ),
                   '.'
                )
             )
          ]
       )
     - 1
    )">
    ]>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:key name="kElementByNamePrefix" match="Element" use="&key;"/>
        <xsl:key name="kElementByName" match="Element" use="@name"/>
        <xsl:template match="Element">
            <xsl:variable name="vNamePrefix" select="&key;"/>
            <xsl:variable name="vCurrentGroup"
             select="key('kElementByNamePrefix',$vNamePrefix)"/>
            <xsl:if test="generate-id() = generate-id($vCurrentGroup[1])">
                <Element name="{$vNamePrefix}">
                    <xsl:apply-templates
                     select="$vCurrentGroup[
                                generate-id()
                              = generate-id(
                                   key('kElementByName',@name)[1]
                                )
                             ]"
                     mode="prefix">
                        <xsl:with-param name="pNamePrefix" select="$vNamePrefix"/>
                    </xsl:apply-templates>
                </Element>
            </xsl:if>
        </xsl:template>
        <xsl:template match="Element" mode="prefix">
            <xsl:param name="pNamePrefix"/>
            <LastToken name="{substring(substring-after(@name,$pNamePrefix),2)}"
                       childCount="{count(key('kElementByName',@name)/Child)}"/>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <Element name="A.B.C">
        <LastToken name="x" childCount="3" />
        <LastToken name="y" childCount="2" />
    </Element>
    <Element name="A.D.E">
        <LastToken name="y" childCount="1" />
        <LastToken name="z" childCount="3" />
    </Element>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file with several child elements. Each child element contains a
To start off, I have this XML file that contains recursive parent-child elements. Here
I have this xml file which has text init. i.e Hi my name is
I ran into the following problem. I have an xml-file like this: <Source Name
I have an XML file which has some values in child Element aswell in
I need to create an xml file that is supposed to look like this.
I have an xml document with a root element, two child elements, 'diagnostic' and
I need to count the number of elements in an XML file that have
I have an xml file like this: <uploads> <upload> <name>asd</name> <type>123</name> </upload> <upload> <name>qwe</name>
I need to read a xml file, but I have this error when try

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.