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

  • Home
  • SEARCH
  • 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 529013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:02:49+00:00 2026-05-13T09:02:49+00:00

Using XML in this format: <?xml version=1.0?> <GetResult version=1.0> <Fetch> <StartTime>2004-08-01 00:00:00</StartTime> <EndTime>2004-08-01 00:00:00</EndTime>

  • 0

Using XML in this format:

<?xml version="1.0"?>
<GetResult version="1.0">
<Fetch>
    <StartTime>2004-08-01 00:00:00</StartTime>
    <EndTime>2004-08-01 00:00:00</EndTime>
</Fetch>
<Items>
    <Item>
        <Name>Item Name Number 1</Name>
        <Data>
            <Datum>
                <Timestamp>2004-07-31 16:00:00+00:00</Timestamp>
                <Value><![CDATA[25]]></Value>
            </Datum>
            <Datum>
                <Timestamp>2004-07-31 18:00:00+00:00</Timestamp>
                <Value><![CDATA[35]]></Value>
            </Datum>
        </Data>
    </Item> 
    <Item>
        <Name>Item Number 2</Name>
        <Data>
            <Datum>
                <Timestamp>2004-07-31 16:00:00+00:00</Timestamp>
                <Value><![CDATA[45]]></Value>
            </Datum>
            <Datum>
                <Timestamp>2004-07-31 17:00:00+00:00</Timestamp>
                <Value><![CDATA[55]]></Value>
            </Datum>
            <Datum>
                <Timestamp>2004-07-31 18:00:00+00:00</Timestamp>
                <Value><![CDATA[65]]></Value>
            </Datum>
        </Data>
    </Item> 
</Items>
</GetResult>

I’d like to be able to produce a table like so, using XSLT:

<table>
  <tr>
    <th>Timestamp</th>
    <th>Item Name Number 1</th>
    <th>Item Number 2</th>
  </tr>
  <tr>
    <td>2004-07-31 16:00:00+00:00</td>
    <td>25</td>
    <td>45</td>
  </tr>
  <tr>
    <td>2004-07-31 17:00:00+00:00</td>
    <td></td>
    <td>55</td>
  </tr>
  <tr>
    <td>2004-07-31 18:00:00+00:00</td>
    <td>35</td>
    <td>65</td>
  </tr>
</table>

This would have to work regardless of how many Items are returned and how many Datums under each item. I’ve read some other answers which are similar without any luck. I’m fairly new to XSLT and it is driving me crazy. A solution for this would be greatly appreciated.

  • 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-13T09:02:49+00:00Added an answer on May 13, 2026 at 9:02 am

    Here is a method that makes use of the rather scary method of Muenchian Grouping, which you will probably see mentioned about if you look at other XSLT issues in StackOverflow, so it is worth knowing. In this instance Muenchian Grouping will be used to loop through distict Timestamp elements.

    First, you define a key to look-up the timestamp elements

    <xsl:key name="Timestamps" match="Timestamp" use="."/>
    

    Thus, if you used this to look-up the key of ‘2004-07-31 16:00:00+00:00’ it would contain two Timestamp, elements, but ‘2004-07-31 17:00:00+00:00’ would only contain one.

    To loop through distinct Timestamp elements, you would first loop through all Timestamp elements, like so

    <xsl:for-each select="//Timestamp">
    

    But you would then need a XSL:IF condition to check the Timestamp element is the first such occurence of that value. This is done by using the key. If the element happens to be first in the key list, then it can be processed.

    <xsl:if test="generate-id(.) = generate-id(key('Timestamps',.)[1])">
    

    generate-id is the method to use when you want to test two elements are the same. Putting it altogether gives:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:key name="Timestamps" match="Timestamp" use="."/>
       <xsl:template match="/">
          <table>
             <tr>
                <th>Timestamp</th>
                <!-- Output the Item headers -->
                <xsl:for-each select="//Item">
                   <th>
                      <xsl:value-of select="Name"/>
                   </th>
                </xsl:for-each>
             </tr>
             <!-- Loop through all Timestamps -->
             <xsl:for-each select="//Timestamp">
                <xsl:sort select="."/>
                <!-- Only process the element if it is the first occurence of this value -->
                <xsl:if test="generate-id(.) = generate-id(key('Timestamps',.)[1])">
                   <xsl:variable name="Timestamp" select="."/>
                   <tr>
                      <td>
                         <xsl:value-of select="."/>
                      </td>
                      <xsl:for-each select="//Item">
                         <td>
                            <!-- Output the relevant Value for the Item -->
                            <xsl:value-of select="Data/Datum[Timestamp=$Timestamp][1]/Value"/>
                         </td>
                      </xsl:for-each>
                   </tr>
                </xsl:if>
             </xsl:for-each>
          </table>
       </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I create xml file with this format using c#? <?xml version=1.0 encoding=utf-8
Using version 2.0.0.1219 I am attempting to self host both a subscriber and publisher
I'm using XSL-FO with Apache FOP to take a sexy looking XML file and
I try many different solution on this site and none seems to work for
I am converting some environment variables to property sheets for some C++ projects. This
I have this function that export a datagridView in Excel sheet : public void
Wondering if I should ALWAYS use the respond_to/format.xxx block in ALL of my actions
I wrote an application in C# for win 7 which used .NET 4.0 and
I have an existing application that has some parts of formatted text-blocks (standard formats
I have a Java application that is generating JasperReports. It will create as many

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.