Start New Discussion within our Software Development Community

Hi ,

I have an xml which is in the following format.

<root>
 <x>
   <y>
    <uri>ssomeuri</uri>
    <date>2012-07-11T10:29:08+00:00</uri>
  </y>
  </x>
 <x>
   <y>
    <uri>ssomeuri2</uri>
    <date>2012-07-11T11:01:08+00:00</uri>
  </y>
  </x>
  </root>

I wanted to get uris in the order of date. I am very new to xpath, can any body help me on this.

the result should be like
ssomeuri2
ssomeuri

Regards
Sri

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes" method ="text"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match ="root">
    <xsl:apply-templates select="x/y">
      <!-- Year -->
      <xsl:sort select="substring(date, 1, 4)" data-type="number" order="descending"/>
      <!-- Month -->
      <xsl:sort select="substring(date, 6, 2)" data-type="number" order="descending"/>
      <!-- Day -->
      <xsl:sort select="substring(date, 9, 2)" data-type="number" order="descending"/>
      <!-- Hour -->
      <xsl:sort select="substring(date, 12, 2)" data-type="number" order="descending"/>
      <!-- Minute -->
      <xsl:sort select="substring(date, 15, 2)" data-type="number" order="descending"/>
      <!-- Second -->
      <xsl:sort select="substring(date, 18, 2)" data-type="number" order="descending"/>
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="y">
    <xsl:value-of select="uri"/>
    <xsl:text>&#0010;</xsl:text>
  </xsl:template>

</xsl:stylesheet>

Have to break down the date string into individual numbers due to XSLT 1.0 only being able to compare numbers and text.

This article has been dead for over six months. Start a new discussion instead.