This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Date Parsing (Was: Document() question)
- From: Jarkko dot Moilanen at uta dot fi
- To: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 12 Jun 2002 10:03:32 +0300 (EEST)
- Subject: [xsl] Re: Date Parsing (Was: Document() question)
- References: <200206112358.53047.pdavis152@attbi.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
This is not what I ment. I ment that I need to read the latest/newest values
from a different xml- file. To be more exact: while processing
000000001001.xml I need the values mentioned before from file TopicIndex.xml.
But thanks for the sorting, which I am familiar already =)
Jarkko
Lainaus Peter Davis <pdavis152@attbi.com>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Tuesday 11 June 2002 22:33, Jarkko.Moilanen@uta.fi wrote:
> > I need to find the latest document from file TopicIndex.xml and insert
> the
> > values to 000000001001.xml file. Values that I need are: SignStatus,
> > DocType, Time, Sender, Subject. The result is shown in html format.
>
> So the hard part is really just finding the "latest" <Information>
> element.
> Fortunately, you're date and time formats are easily parseable, and more
> importantly, the parts of the date and time (1) begin with the most
> significant digits, and (2) are padded with 0's for numbers less than
> 10.
> Those qualities mean that you can use <xsl:sort> to sort the date and
> time
> alphabetically, and then select the latest one from the sorted list.
>
> Once you sort the list of <Information> elements, you have to choose the
> last
> one from the list. The easiest way to do that is with the position()
> and
> last() functions, which will let you test the position of each
> <Information>
> element in the sorted list. Finally, once you get the desired
> <Information>
> element, you just copy the necessary child elements to the result tree.
>
> <xsl:template match="Document">
> <Result>
> <xsl:apply-templates select="Information">
> <!-- this stage is simple because your date and time formats are
> already
> sortable; other formats might require additional processing,
> since
> XPath does not have a build in date parser/sorter -->
> <xsl:sort select="Time"/>
> <!-- sort by Time (date) first, and then by the clock if two dates
> are
> the same -->
> <xsl:sort select="Clock"/>
> </xsl:apply-templates>
> </Result>
> </xsl:template>
>
> <xsl:template match="Information">
> <!-- if the current element is the last element in the sorted list -->
> <xsl:if test="position() = last()">
> <xsl:copy-of select="SignStatus"/>
> <xsl:copy-of select="DocType"/>
> <xsl:copy-of select="Time"/>
> <xsl:copy-of select="Sender"/>
> <xsl:copy-of select="Subject"/>
> </xsl:if>
> </xsl:template>
>
> HTH
>
> - --
> Peter Davis
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.7 (GNU/Linux)
>
> iD8DBQE9BvEqNSZCJx7tYycRAkVRAKCzbd8iuy1XyLDspP5azvyUTUg8fgCdGJGB
> m1MKktmxDH86UycTCk2hnpk=
> =PPzz
> -----END PGP SIGNATURE-----
>
>
******************************************************************
Jarkko Moilanen *You are wise, witty, and wonderful, *
Researcher/ ITCM *but you spend too much time *
jm60697@uta.fi *reading this sort of trash. *
www.uta.fi/~jm60697 * *
GSM: +358 50 3766 927 * *
******************************************************************
* ITCM | Information Technology and Crisis Management *
* http://www.itcm.org *
******************************************************************
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list