From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
Mike O'Connor <ipso.vocat@gmail.com>
Subject: Re: XML to ConTeXt: converting date attribute from ISO date
Date: Wed, 15 Aug 2018 14:04:05 +0200 [thread overview]
Message-ID: <a25f7e83-ccad-4e4c-2f31-f57d9770a53e@xs4all.nl> (raw)
In-Reply-To: <16FB1586-A34F-488F-807C-4D4C15826261@gmail.com>
On 8/15/2018 12:27 PM, Mike O'Connor wrote:
> G’Day,
>
> Having a first go at converting TEI XML to ConTeXt.
>
> Steep learning curve, but easier (for me) than XSLT, and first results
> were amazing. Using
> http://www.pragma-ade.com/general/manuals/xml-mkiv.pdf as a guide.
>
> Currently stuck on converting an ISO format date (eg. 1908-01-10) into
> something more readable (eg. 10 January 1908) in the output. I presume
> I should create a function (?luacode) that can take any ISO value and
> output the readable form. The following works but seems to me inefficient.
>
> Grateful for any pointers.
>
> Mike
>
> Here is my MWE:
>
> \startbuffer[demo]
> <TEI>
> <text>
> <body>
> <div type="letter">
> <opener>
> <date when-iso="1908-01-10"
> type="divDate">10.I.08</date>
> </opener>
> <closer>
> <date when-iso="1908-03-19" type="secondDate">19 Mar '08</date>
> </closer>
> </div>
> </body>
> </text>
> </TEI>
> \stopbuffer
>
> \startxmlsetups xml:initialize
> \xmlsetsetup{#1}{date}{xml:date}
> \stopxmlsetups
> \xmlregistersetup{xml:initialize}
>
> \startxmlsetups xml:date
> \xmldoifelse {#1}{.[@type='divDate']} {
> \def\docdate{\ctxlua{
> local tyear = string.sub('\xmlatt{#1}{when-iso}',1,4)
> local tmonth = string.sub('\xmlatt{#1}{when-iso}',6,7)
> local tday = string.sub('\xmlatt{#1}{when-iso}',9,10)
> context.date{d = tday, m = tmonth, y = tyear}
> }}
> \docdate[day,month,year] = Document Date \par
> } {
> \def\docdate{\ctxlua{
> local tyear = string.sub('\xmlatt{#1}{when-iso}',1,4)
> local tmonth = string.sub('\xmlatt{#1}{when-iso}',6,7)
> local tday = string.sub('\xmlatt{#1}{when-iso}',9,10)
> context.date{d = tday, m = tmonth, y = tyear}
> }}
> \docdate[day,month,year] = Event Date\par
> }
> \stopxmlsetups
>
> \starttext
> \xmlprocessbuffer{main}{demo}{}
> \stoptext
Can be wikified ...
\startluacode
function xml.finalizers.tex.MyDate(e,what,how)
local t = string.split(e[1].at[what],"-")
context.date(
{ y = t[1], m = t[2], d = t[3] },
{ how }
)
end
\stopluacode
\startxmlsetups xml:date
\xmldoifelse {#1}{.[@type='divDate']} {
\xmlfilter{#1}{./MyDate("when-iso","day,month,year")}\
Document Date \par
} {
\xmlfilter{#1}{./MyDate("when-iso","day,month,year")}\
Event Date\par
}
\stopxmlsetups
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2018-08-15 12:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-30 14:17 Outputting custom types in MKiv bibliography Mike O'Connor
2016-05-05 8:39 ` luigi scarso
2018-08-15 10:27 ` XML to ConTeXt: converting date attribute from ISO date Mike O'Connor
2018-08-15 12:04 ` Hans Hagen [this message]
2020-03-11 13:14 ` Axel Kielhorn
2020-03-11 14:01 ` Hans Hagen
[not found] ` <B77FE72A-BC5E-4E34-A859-8CD860E9B978@axelkielhorn.de>
[not found] ` <faf46a0b-2726-9dd8-d62b-8288e7fb1849@xs4all.nl>
2020-03-11 14:38 ` Axel Kielhorn
2020-03-11 15:54 ` Axel Kielhorn
2020-03-11 19:22 ` Hans Hagen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a25f7e83-ccad-4e4c-2f31-f57d9770a53e@xs4all.nl \
--to=j.hagen@xs4all.nl \
--cc=ipso.vocat@gmail.com \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).