This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: 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 13:18:11 +0300 (EEST)
- Subject: RE: [xsl] Re: Date Parsing (Was: Document() question)
- References: <002c01c211f0$f535c440$6401a8c0@pcukmka>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Yes. It was quite simple.
Here is how I did it (dunno if its best possible way, but...)
xsl-file:
<snip>
<xsl:variable name="TopicIndex" select="document('TopicIndex.xml')"/>
// declare variable where the external xml file is named
<xsl:variable name="recent">
<xsl:for-each select="$TopicIndex//Document//Information">
<xsl:sort select="Time" order="ascending" />
<xsl:sort select="Clock" order="ascending" />
<xsl:if test="position() = last()">
<a href="html?{Subject/@id}{Subject/@id2}">
<xsl:apply-templates select="Subject" /></a>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="sender">
<xsl:for-each select="$TopicIndex//Document//Information">
<xsl:sort select="Time" order="ascending" />
<xsl:sort select="Clock" order="ascending" />
<xsl:if test="position() = last()">
<xsl:value-of select="Sender" />
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="Type">
<xsl:for-each select="$TopicIndex//Document//Information">
<xsl:sort select="Time" order="ascending" />
<xsl:sort select="Clock" order="ascending" />
<xsl:if test="position() = last()">
<xsl:value-of select="DocType" />
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="NumberOfMessages">
<xsl:for-each select="$TopicIndex//Document">
<xsl:value-of select="count(Information)" />
</xsl:for-each>
</xsl:variable>
</snip>
xml file (external):
<snip>
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<Document View="Week" Value="23">
<Information SignStatus="Open">
<DocType>CDR</DocType>
<Time>01/09/09</Time>
<Clock>01:45:03</Clock>
<Sender>Moilanen Jarkko</Sender>
<Subject id="0000000004" id2="001">3. JPr hyökkäyskäsky Haminassa</Subject>
<Subject2>Xsl- muutokset</Subject2>
<Infofield>
<Topic>Include hommat ei pelaa</Topic>
</Infofield>
</Information>
<Information SignStatus="Open">
<DocType>CDR</DocType>
<Time>01/09/10</Time>
<Clock>11:45:03</Clock>
<Sender>Moilanen Jarkko</Sender>
<Subject id="0000000004" id2="002">RE:3. JPr hyökkäyskäsky
Haminassa</Subject>
<Subject2>Xsl- muutokset</Subject2>
<Infofield>
<Topic>Include hommat ei pelaa</Topic>
</Infofield>
</Information>
</Document>
</snip>
I understood that this can also be done by xsl:key, right?
Cheers
Jarkko
> It's not at all clear from your posting where your problems lie. It
> doesn't sound like a difficult problem, so there must be some simple
> point that you have missed. Perhaps if you show us your stylesheet we
> will be able to tell you where you are going wrong.
>
> Michael Kay
> Software AG
> home: Michael.H.Kay@ntlworld.com
> work: Michael.Kay@softwareag.com
>
> > -----Original Message-----
> > From: owner-xsl-list@lists.mulberrytech.com
> > [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of
> > Jarkko.Moilanen@uta.fi
> > Sent: 12 June 2002 08:04
> > To: xsl-list@lists.mulberrytech.com
> > Subject: [xsl] Re: Date Parsing (Was: Document() question)
> >
> >
> >
> > 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
> >
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
******************************************************************
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