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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:39:36+00:00 2026-06-14T21:39:36+00:00

This question follows on from query XSLT: Sorting based on sum of values from

  • 0

This question follows on from query XSLT: Sorting based on sum of values from other nodes

I have this piece of xslt (thanks to Demitre) which I’ve modified to receive a parameter ‘Gait’ which can have values ‘P’ (Pace), ‘T’ (Trot) or ‘A’ (All):

<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="kOffspring" match="Horse" use="SireID"/>
 <xsl:param name="Gait"/>

 <xsl:template match="/*">
  <xsl:apply-templates select="Sires/Sire">
   <xsl:sort select="sum(key('kOffspring', ID)/*/Stakes)"
             data-type="number" order="descending"/>
  </xsl:apply-templates>
 </xsl:template>

 <xsl:template match="Sire">
     Sire <xsl:value-of select="concat(ID,' (', Name, ') Stakes: ')"/>
   <xsl:value-of select="sum(key('kOffspring', ID)/*/Stakes)"/>
 </xsl:template>
 <xsl:template match="text()"/>
</xsl:stylesheet>

In the above code is this piece

sum(key('kOffspring', ID)/*/Stakes

Is there a way to substitute the asterisk part with the name of a node in xml tree depending on what value was passed in for gait?

Super simplified xml is:

<t>
    <Horses>
        <Horse>
            <ID>5</ID>
            <Name>hrsE</Name>
            <SireID>101</SireID>
            <Pace>
                <Stakes>100</Stakes>
            </Pace>
            <Trot>
                <Stakes>300</Stakes>
            </Trot>
        </Horse>
    </Horses>
    <Sires>
        <Sire>
            <ID>101</ID>
            <Name>srA</Name>
            <LiveFoalsALL>117</LiveFoalsALL>
        </Sire>
    </Sires>
</t>

When $Gait is ‘A’ I want sum(key(‘kOffspring’, ID)/*/Stakes (look in all sub-nodes of Horse)

When $Gait is ‘P’ I want sum(key(‘kOffspring’, ID)/Pace/Stakes (look in the Pace node only to find Stakes)

When $Gait is ‘T’ I want sum(key(‘kOffspring’, ID)/Trot/Stakes (look in the Trot node only to find Stakes)

So this is super-simplified example. I’m trying to stop having to duplicate hundred lines of code to cater to different values of $Gait. I played around trying use variables but couldn’t see how to change the value of the node path when it is using a key in the path. I saw I could potentially use a choose statement in the ‘match=”/*”‘ template but that was only for sorting, I was still stuck when I got to the ‘Sire’ template – didn’t want to have to put ‘choose’ around all the multitude of ‘value-of select’ statements I have.

Thanks for any suggestions.
Regards,
Bryce Stenberg.

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

    Just use

    sum(key('kOffspring', ID)/*[name()=$Gait]/Stakes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL query as follows: SELECT KeywordText, SUM(Frequency) AS Frequency FROM Keyword,
This question follows on from the questions here and here . I have recently
This question follows on from a previous question, that has raised a further issue.
This question follows on from a previous question. However stackoverflow presents me from commenting
this follows on from my last question which I thought was answered but for
This problem follows on from a previous question . When I run the following
This is a follow up from my previous question I have this code basically
This question follows on from a question I asked yesterday about why using the
This question follows on from the problem posted here when i run explain I
This follows on from this question: Modify XML in SQL server to add a

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.