Re: [NTG-context] XML to ConTeXt: converting date attribute from ISO date

2020-03-11 Thread Hans Hagen

On 3/11/2020 4:54 PM, Axel Kielhorn wrote:

Hello Hans and mailing list!

Thank you so much.

With this example and the help I received earlier from Massi,
I’ve been able to write my first finalizer today.

It is amazing how powerful luatex is.


indeed (and luametatex is supposed to be even bit more powerful)


My project needs some cleanup and documentation but I hope to put it on GitHub 
soon.
After that I will try to put a minimal version into the wiki.

that would be nice. thanks

Hans

-
  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
___


Re: [NTG-context] XML to ConTeXt: converting date attribute from ISO date

2020-03-11 Thread Axel Kielhorn
Hello Hans and mailing list!

Thank you so much.

With this example and the help I received earlier from Massi, 
I’ve been able to write my first finalizer today.

It is amazing how powerful luatex is.

My project needs some cleanup and documentation but I hope to put it on GitHub 
soon.
After that I will try to put a minimal version into the wiki.

Greetings Axel
___
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
___


Re: [NTG-context] XML to ConTeXt: converting date attribute from ISO date

2020-03-11 Thread Axel Kielhorn


> Am 11.03.2020 um 15:19 schrieb Hans Hagen :
> 
> On 3/11/2020 3:12 PM, Axel Kielhorn wrote:
>>> Am 11.03.2020 um 15:01 schrieb Hans Hagen :
>>> 
>>> On 3/11/2020 2:14 PM, Axel Kielhorn wrote:
 
 Had to change it to:
 \startluacode
function xml.finalizers.tex.MyDate(e,what,how)
local ee = e[1].at[what]
local t = (string.split(ee,"-"))
context.date(
{ y = t[1], m = t[2], d = t[3] },
{ how }
)
end
 \stopluacode
>>> You mean the () around the split? weird. Anyway, there's also a time 
>>> splitter (dedicated to Alan who needed one):
>> No, sorry that’s an artifact from testing.
>> I had to assign:
>> local ee = e[1].at[what]
>> and
>> string.split(ee,"-")
>> in two steps while the original had
>> local t = string.split(e[1].at[what],"-")
> still strange because it's one value, if it were multiple you could do

This is strange.
Now it works.

Earlier I had context.date complaining that it got a table and not a string.
That’s why I took the t = assignment apart into pieces.

Now I copied the code from the original reply and it works.

Sorry for the noise.

Axel


___
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
___


Re: [NTG-context] XML to ConTeXt: converting date attribute from ISO date

2020-03-11 Thread Hans Hagen

On 3/11/2020 2:14 PM, Axel Kielhorn wrote:




Am 15.08.2018 um 14:04 schrieb Hans Hagen :

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]

 
 
 
 
 10.I.08
 
 
19 Mar '08
 
 
 
 

\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


I couldn’t get this to work.
Had to change it to:

\startluacode
function xml.finalizers.tex.MyDate(e,what,how)
local ee = e[1].at[what]
local t = (string.split(ee,"-"))
context.date(
{ y = t[1], m = t[2], d = t[3] },
{ how }
)
end
\stopluacode
You mean the () around the split? weird. Anyway, there's also a time 
splitter (dedicated to Alan who needed one):


print(os.time(utilities.parsers.totime("2019-03-05 12:12:12")))
print(os.time(utilities.parsers.totime("2019/03/05 12:12:12")))
print(os.time(utilities.parsers.totime("05-03-2019 12:12:12")))
print(os.time(utilities.parsers.totime("05/03/2019 12:12:12")))

inspect(utilities.parsers.totime("2019-03-05 12:12:12"))
inspect(utilities.parsers.totime("2019/03/05 12:12:12"))
inspect(utilities.parsers.totime("05-03-2019 12:12:12"))
inspect(utilities.parsers.totime("05/03/2019 12:12:12"))


-
  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
___


Re: [NTG-context] XML to ConTeXt: converting date attribute from ISO date

2020-03-11 Thread Axel Kielhorn


> Am 15.08.2018 um 14:04 schrieb Hans Hagen :
> 
> 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]
>> 
>> 
>> 
>> 
>> 
>> 10.I.08
>> 
>> 
>> 19 Mar '08
>> 
>> 
>> 
>> 
>> 
>> \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

I couldn’t get this to work.
Had to change it to:

\startluacode
   function xml.finalizers.tex.MyDate(e,what,how)
   local ee = e[1].at[what]
   local t = (string.split(ee,"-"))
   context.date(
   { y = t[1], m = t[2], d = t[3] },
   { how }
   ) 
   end
\stopluacode

mtx-context | ConTeXt Process Management 1.03
mtx-context |
mtx-context | main context file: /Volumes/Macintosh 
HD/usr/local/texlive/context-109/tex/texmf-context/tex/context/base/mkiv/context.mkiv
mtx-context | current version: 2020.01.30 14:13
mtx-context | main context file: /Volumes/Macintosh 
HD/usr/local/texlive/context-109/tex/texmf-context/tex/context/base/mkiv/context.mkxl
mtx-context | current version: 2020.01.30 14:13

Greetings Axel

___
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
___


Re: [NTG-context] XML to ConTeXt: converting date attribute from ISO date

2018-08-15 Thread Hans Hagen

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]

     
         
             
                 
                     type="divDate">10.I.08

                 
                 
19 Mar '08
                 
             
         
     

\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
___

[NTG-context] XML to ConTeXt: converting date attribute from ISO date

2018-08-15 Thread Mike O'Connor
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]





10.I.08


19 Mar 
'08





\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___
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
___