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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:37:10+00:00 2026-05-14T21:37:10+00:00

Using XSLT 1.0 – I have the following xml and I an trying to

  • 0

Using XSLT 1.0 – I have the following xml and I an trying to perform the following

  • Group By the first Field where id=”1923″ if the value attribute is the same
  • and average all the fields with id=”3095″ using the value attribute
  • and average all the fields with id=”3095″ using the value attribute

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="Trans.xsl"?>
 <Results>
  <List count="6">
   <Record contentId="1017835" finalFlag="True" levelId="" moduleId="152" primarySortId="" secondarySortId="" parentId="0" row="1" parentRow="" >
    <Field id="1923" type="1" value="Test 1"></Field>
    <Field id="3095" type="4" valueID="3809" value="1" parentId="3809" parentName="5" ></Field>
    <Field id="3096" type="4" valueID="3809" value="1" parentId="3809" parentName="5" ></Field>
   </Record>
   <Record contentId="1017828" finalFlag="True" levelId="" moduleId="152" primarySortId="" secondarySortId="" parentId="0" row="2" parentRow="" >
    <Field id="1923" type="1" value="Test 2"></Field>
    <Field id="3095" type="4" valueID="729" value="2" parentId="729" parentName="2" ></Field>
    <Field id="3096" type="4" valueID="3809" value="5" parentId="3809" parentName="5" ></Field>
   </Record>
   <Record contentId="1017978" finalFlag="True" levelId="" moduleId="152" primarySortId="" secondarySortId="" parentId="0" row="3" parentRow="" >
    <Field id="1923" type="1" value="Test 3"></Field>
    <Field id="3095" type="4" valueID="3808" value="4" parentId="3808" parentName="4" ></Field>
    <Field id="3096" type="4" valueID="3808" value="4" parentId="3808" parentName="4" ></Field>
   </Record>
   <Record contentId="1035463" finalFlag="True" levelId="" moduleId="152" primarySortId="" secondarySortId="" parentId="0" row="4" parentRow="" >
    <Field id="1923" type="1" value="Test 2"></Field>
    <Field id="3095" type="4" valueID="3808" value="4" parentId="3808" parentName="4" ></Field>
    <Field id="3096" type="4" valueID="730" value="3" parentId="730" parentName="3" ></Field>
   </Record>
   <Record contentId="1017985" finalFlag="True" levelId="" moduleId="152" primarySortId="" secondarySortId="" parentId="0" row="5" parentRow="" >
    <Field id="1923" type="1" value="Test 1"></Field>
    <Field id="3095" type="4" valueID="113690" value="10" parentId="113690" parentName="10" ></Field>
    <Field id="3096" type="4" valueID="113690" value="10" parentId="113690" parentName="10" ></Field>
   </Record>
   <Record contentId="1017835" finalFlag="True" levelId="" moduleId="152" primarySortId="" secondarySortId="" parentId="0" row="6" parentRow="" >
    <Field id="1923" type="1" value="Test 1"></Field>
    <Field id="3095" type="4" valueID="3809" value="5" parentId="3809" parentName="5" ></Field>
    <Field id="3096" type="4" valueID="3809" value="5" parentId="3809" parentName="5" ></Field>
   </Record>
  </List>
 </Results>

Trying to produce the following using trans.xsl:

<Records>
 <Data>
  <Text1923>Test 1</Text1923>
  <Avg3095>5.33</Avg3095>
  <Avg3096>5.33</Avg3096>
 </Data>
 <Data>
  <Text1923>Test 2</Text1923>
  <Avg3095>3</Avg3095>
  <Avg3096>4</Avg3096>
 </Data>
 <Data>
  <Text1923>Test 3</Text1923>
  <Avg3095>4</Avg3095>
  <Avg3096>4</Avg3096>
 </Data>
</Records>
  • 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-14T21:37:10+00:00Added an answer on May 14, 2026 at 9:37 pm

    Here is a simple XSLT 1.0 solution using the Muenchian Grouping Method:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:key name="kFieldById" match="Field"
      use="@id"/>
    
     <xsl:key name="kField1923"
      match="Field[@id='1923']" use="@value"/>
    
     <xsl:template match="/">
      <Records>
        <xsl:for-each select=
        "key('kFieldById', '1923')
             [generate-id()
             =
              generate-id(key('kField1923',
                              @value
                              )
                               [1]
                          )
              ]
        ">
         <Data>
             <Text1923>
               <xsl:value-of select="@value"/>
             </Text1923>
    
             <xsl:variable name="vSubfield3095" select=
               "key('kField1923',@value)
                             /../Field[@id='3095']
               "/>
    
             <xsl:variable name="vSubfield3096" select=
               "key('kField1923',@value)
                             /../Field[@id='3096']
               "/>
    
             <Avg3095>
               <xsl:value-of select=
                "sum($vSubfield3095/@value)
                div
                 count($vSubfield3095)
                "/>
             </Avg3095>
    
             <Avg3096>
               <xsl:value-of select=
                "sum($vSubfield3096/@value)
                div
                 count($vSubfield3096)
                "/>
             </Avg3096>
         </Data>
        </xsl:for-each>
      </Records>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document, the wanted, correct resul is produced:

    <Records>
       <Data>
          <Text1923>Test 1</Text1923>
          <Avg3095>5.333333333333333</Avg3095>
          <Avg3096>5.333333333333333</Avg3096>
       </Data>
       <Data>
          <Text1923>Test 2</Text1923>
          <Avg3095>3</Avg3095>
          <Avg3096>4</Avg3096>
       </Data>
       <Data>
          <Text1923>Test 3</Text1923>
          <Avg3095>4</Avg3095>
          <Avg3096>4</Avg3096>
       </Data>
    </Records>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am transforming XML into HTML using XSLT. I have the following XML structure:
I'm transforming an XML Schema using XSLT 2.0. The first schema (s1.xsd) imports a
I am trying to convert an HTML file into XML file using XSLT (Using
Using XSLT, how can I wrap siblings that share the same value for an
Using XSLT 1.0 & receive dates in the following format: 20111129060804 and I have
I am using XSLT and XML, I have below XML format with me. <?xml
This is my first time using XSLT. I'm trying to create a file that
I am trying to do a simple transform of XML using XSLT to generate
I am using XSLT and XML. I have got below XML. <documentCountryInformation> <countryCode>US</countryCode> <countryName>United
I am using XSLT 1.0 Suppose I have an xml that has certain num

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.