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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:18:41+00:00 2026-06-16T02:18:41+00:00

I need to do a bit tricky mapping using xslt 1.0. need to do

  • 0

I need to do a bit tricky mapping using xslt 1.0. need to do grouping only on the date part of the datetime element. However the element contains the both date and time.Also after grouping need to add the hours.

Here is the input:

<Records>
   <Record>
      <empid>1</empid>
      <datetime>10/10/2010 11:11:00 AM</datetime>
      <hours>5</hours>
    </Record>
    <Record>            
      <empid>1</empid>
      <datetime>10/10/2010 10:11:00 AM</datetime>
      <hours>5</hours>
    </Record>
    <Record>   
      <empid>1</empid>           
      <datetime>10/11/2010 11:11:00 AM</datetime>
      <hours>5</hours>
    </Record>
    <Record>   
       <empid>2</empid>
       <datetime>10/10/2010 10:11:00 AM</datetime>
       <hours>2</hours>
    </Record>
    <Record> 
      <empid>2</empid>
      <datetime>10/10/2010 9:11:00 AM</datetime>
      <hours>5</hours>  
     </Record>    
  </Records>   

Expected output is:

  <Records>
      <Record>
       <empid>1</empid>
      <detail>     
         <date>10/10/2010</date>
         <hours>10</hours>
      </detail> 
     <detail>
        <date>10/11/2010</date>
        <hours>5</hours>
     </detail>
    </Record>
    <Record>
       <empid>2</empid>
       <detail>
          <date>10/10/2010</date>
          <hours>7</hours>
       </detail>
    </Record>
 </Records>

Appreciate for any help.

  • 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-16T02:18:43+00:00Added an answer on June 16, 2026 at 2:18 am

    This transformation:

    <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:key name="kRecById" match="Record" use="empid"/>
     <xsl:key name="kRecByDateId" match="Record"
              use="concat(empid,'+',substring-before(datetime, ' '))"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match=
      "Record[generate-id()=generate-id(key('kRecById', empid)[1])]">
      <Record>
       <xsl:apply-templates select="empid"/>
       <xsl:apply-templates mode="inGroup" select=
        "key('kRecById', empid)
                    [generate-id()
                    =
                     generate-id(key('kRecByDateId',
                                 concat(empid,'+',substring-before(datetime, ' ')))[1])]"/>
      </Record>
     </xsl:template>
    
     <xsl:template match="Record" mode="inGroup">
       <detail>
         <date><xsl:value-of select="substring-before(datetime, ' ')"/></date>
         <hours><xsl:value-of select=
         "sum(key('kRecByDateId',
                  concat(empid,'+',substring-before(datetime, ' '))
                  )/hours)"/>
         </hours>
       </detail>
     </xsl:template>
     <xsl:template match="Record"/>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <Records>
        <Record>
            <empid>1</empid>
            <datetime>10/10/2010 11:11:00 AM</datetime>
            <hours>5</hours>
        </Record>
        <Record>
            <empid>1</empid>
            <datetime>10/10/2010 10:11:00 AM</datetime>
            <hours>5</hours>
        </Record>
        <Record>
            <empid>1</empid>
            <datetime>10/11/2010 11:11:00 AM</datetime>
            <hours>5</hours>
        </Record>
        <Record>
            <empid>2</empid>
            <datetime>10/10/2010 10:11:00 AM</datetime>
            <hours>2</hours>
        </Record>
        <Record>
            <empid>2</empid>
            <datetime>10/10/2010 9:11:00 AM</datetime>
            <hours>5</hours>
        </Record>
    </Records>
    

    produces the wanted, correct result:

    <Records>
       <Record>
          <empid>1</empid>
          <detail>
             <date>10/10/2010</date>
             <hours>10</hours>
          </detail>
          <detail>
             <date>10/11/2010</date>
             <hours>5</hours>
          </detail>
       </Record>
       <Record>
          <empid>2</empid>
          <detail>
             <date>10/10/2010</date>
             <hours>7</hours>
          </detail>
       </Record>
    </Records>
    

    Explanation:

    Two nested Muenchian grouping s, the inner using a composite key.

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

Sidebar

Related Questions

I am fairly new to using Linq which is turning out a bit tricky
This one's a bit too tricky for my SQL-foo. What I need to do
This is a little bit tricky, so if you need more information, don't hesitate!
I read the answer in parashift but I need bit details as to why
I need a bit of help from any of the coders out there..... Currently,
I need a bit of help with some Ruby array jujitsu. I have the
I need a bit of help; I'm helping a friend port a Delphi app
I don't know MySQL very well so I need a bit of help with
I need a wee bit of help with css formatting on my website. Please
Just need a little bit of Javascript to warn people that press the back

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.