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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:11:38+00:00 2026-05-16T06:11:38+00:00

I have the following xml <Values> <New> <value>110</value> <date>2009-10-15</date> </New> <Previous> <value>100</value> <date>2010-10-15</date> </Previous>

  • 0

I have the following xml

<Values>
 <New>
    <value>110</value>
    <date>2009-10-15</date>
  </New>
  <Previous>
    <value>100</value>
    <date>2010-10-15</date>
  </Previous>
  <Previous>
    <value>130</value>
    <date>2008-10-15</date>
  </Previous>
</Values>

I am using the following xsl

 <xsl:variable name="mergedData">
       <xsl:for-each select="//Values/New">
             <xsl:copy-of select="."/>
       </xsl:for-each>
       <xsl:for-each select="//Values/Previous">
             <xsl:copy-of select="."/>
       </xsl:for-each>
    </xsl:variable>


<xsl:for-each select="msxsl:node-set($mergedData)">
     <xsl:sort order="descending" select="substring(date,1,4)"/>
     <xsl:sort order="descending" select="substring(date,6,2)"/>
     <xsl:sort order="descending" select="substring(date,9,2)"/>
         <xsl:if test="position()=1">
              <xsl:value-of select="."/>
          </xsl:if>
</xsl:for-each>

And I get the following.

110 2009-10-15 100 2010-10-15 130 2008-10-15

It does no seems to sort by date and its giving me back a lump of code I need to be sorted by date and been able to manipulate data so I can put them in table rows.

Like this.

110 2009-10-15 
100 2010-10-15 
130 2008-10-15
  • 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-16T06:11:39+00:00Added an answer on May 16, 2026 at 6:11 am

    It does no seems to sort by date and
    its giving me back a lump of code I
    need to be sorted by date and been
    able to manipulate data so I can put
    them in table rows.

    Like this.

    110 2009-10-15  
    100 2010-10-15  
    130 2008-10-15
    

    No, the code (if it were correct) would output the string value of one of the New or Previous elements with maximum date.

    Here is the main problem in your code:

    <xsl:for-each select="msxsl:node-set($mergedData)"> 
    

    the msxsl:node-set() extension function returns a document tree — not a top element or an XML fragment. To put it in other words, it returns the root node: / of this document tree.

    Therefore, the <xsl:for-each> above selects a single node only, and this node has children that are only New or Previous elements. Therefore, there is no sort, because the result of sorting a single node is always this same node.

    Then later in the code:

    <xsl:value-of select="."/>
    

    Because . is the root node of the temporary tree, the above xslt instruction produces the string value of the whole temporary tree — that is, the concatenation, in document order, of all text nodes in this temporary tree. This is exactly what you complain of getting.

    Solution:

    Replace:

    <xsl:for-each select="msxsl:node-set($mergedData)"> 
    

    with:

    <xsl:for-each select="msxsl:node-set($mergedData)/*"> 
    

    Now, the select attribute of xsl:for-each selects all New and Previous top elements in the tree, as obviously was desired.

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

Sidebar

Related Questions

I have the following XML: <data> <page id=1118> <itms> <values> <value>1104</value> </values> </itms> </page>
I have the following xml that I need to get 2 values (see *
I have following xml and I want to fetch the value of node which
I current have the following XML fragment that I'm parsing to read its values
I have the following xml I need to read the values of: <po-response xmlns=http://test.com<
I have some XML in the following format: <ObjectData> <ModelName>MODEL_123</ModelName> <ObjectName>OBJECT_A</ObjectName> <Values> <KeyValuePair> <Key>NAME</Key>
Say I have this following XML structure: <?xml version=1.0 encoding=UTF-8?> <main> <parent> <child1>some value</child1>
Hi I have the following xml <?xml version=1.0 encoding=UTF-8?> <root> <item> <name>john</name> <year>2010</year> </item>
I have the following code which generates XML: $dom = new DomDocument('1.0'); ...snip adding
I have following XML, and i wish to save its data in my SQL

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.