* [NTG-context] Map XML attributes to variables, dynamically
@ 2023-08-10 7:10 Thangalin
2023-08-10 7:43 ` [NTG-context] " Hans Hagen
0 siblings, 1 reply; 6+ messages in thread
From: Thangalin @ 2023-08-10 7:10 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 1563 bytes --]
Hello!
A Markdown document resembles the following:
::: {.concurrent title="Berth 5" location="San Diego"}
Text Goes Here
:::
::: {.concurrent title="Road" location="Beale AFB"}
Different Text Goes Here
:::
The XHTML generated from that document resembles:
<div class="concurrent" data-title="Berth 5" data-location="San Diego">
Text Goes Here
</div>
<div class="concurrent" data-title="Road" data-location="Beale AFB">
Different Text Goes Here
</div>
Environments for the DIV element gets translated using:
\startxmlsetups xml:div
\start[\xmlatt{#1}{class}]\xmlflush{#1}\stop
\stopxmlsetups
This creates "\startconcurrent" and "\stopconcurrent", which are later
defined using "\definestartstop[concurrent]".
I'd like to dynamically define all the data- attributes to make key/value
pairs accessible from the document. For example, I have this:
\definestartstop[concurrent][
before={%
\blank[big]%
\setMPtext{1}{Berth 5}%
\startTextConcurrentFrame},
after={\stopTextConcurrentFrame\blank[big]},
]
I'd like to replace \setMPText calls with a reference to a dynamically
created variable reference. For example:
\setMPtext{1}{\usermap[concurrent.title]}
\setMPtext{2}{\usermap[concurrent.location]}
I can verify the attribute values exist by exporting them to the document:
\startxmlsetups xml:div
title:\xmlatt{#1}{data-title} location:\xmlatt{#1}{data-location}
\start[\xmlatt{#1}{class}]\xmlflush{#1}\stop
\stopxmlsetups
How would you change the xml:div setup to create a map of its attributes as
key/value pairs?
Thank you!
[-- Attachment #1.2: Type: text/html, Size: 2296 bytes --]
[-- Attachment #2: Type: text/plain, Size: 495 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* [NTG-context] Re: Map XML attributes to variables, dynamically
2023-08-10 7:10 [NTG-context] Map XML attributes to variables, dynamically Thangalin
@ 2023-08-10 7:43 ` Hans Hagen
2023-08-10 8:14 ` Thangalin
0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen @ 2023-08-10 7:43 UTC (permalink / raw)
To: ntg-context
On 8/10/2023 9:10 AM, Thangalin wrote:
> Environments for the DIV element gets translated using:
>
> \startxmlsetups xml:div
\setvariable {div} {\xmlatt{#1}{class}} {#1}
> \start[\xmlatt{#1}{class}]\xmlflush{#1}\stop
> \stopxmlsetups
> \setMPtext{1}{\usermap[concurrent.title]}
> \setMPtext{2}{\usermap[concurrent.location]}
\setMPtext{1}{%
\xmlatt {\getvariable {div} {concurrent} {title}%
}
> I can verify the attribute values exist by exporting them to the document:
something like that .. untested as no mwe
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 / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* [NTG-context] Re: Map XML attributes to variables, dynamically
2023-08-10 7:43 ` [NTG-context] " Hans Hagen
@ 2023-08-10 8:14 ` Thangalin
2023-08-10 8:37 ` Hans Hagen
0 siblings, 1 reply; 6+ messages in thread
From: Thangalin @ 2023-08-10 8:14 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 2588 bytes --]
Here's an MWE:
% SOT
\startbuffer[demo]
<html>
<body>
<div class="concurrent" data-title="Berth 5" data-location="San Diego">
Text Goes Here
</div>
<div class="concurrent" data-title="Road" data-location="Beale AFB">
Different Text Goes Here
</div>
</body>
</html>
\stopbuffer
\startxmlsetups xml:xhtml
\xmlsetsetup{\xmldocument}{*}{-}
\xmlsetsetup{\xmldocument}{html|body}{xml:*}
\xmlsetsetup{\xmldocument}{div}{xml:*}
\stopxmlsetups
\xmlregistersetup{xml:xhtml}
\startxmlsetups xml:html
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:body
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:div
\setvariable{div}{\xmlatt{#1}{class}}{#1}
\start[\xmlatt{#1}{class}]\xmlflush{#1}\stop
\stopxmlsetups
\definestartstop[concurrent][
before={TITLE: \xmlatt{\getvariable {div} {concurrent} {title}}},
]
\starttext
\xmlprocessbuffer{main}{demo}{}
\stoptext
% EOT
It doesn't look like the variables are taking, regardless of whether
{title} or {data-title} are used.
On Thu, Aug 10, 2023 at 12:44 AM Hans Hagen <j.hagen@xs4all.nl> wrote:
> On 8/10/2023 9:10 AM, Thangalin wrote:
>
> > Environments for the DIV element gets translated using:
> >
> > \startxmlsetups xml:div
>
> \setvariable {div} {\xmlatt{#1}{class}} {#1}
>
> > \start[\xmlatt{#1}{class}]\xmlflush{#1}\stop
> > \stopxmlsetups
> > \setMPtext{1}{\usermap[concurrent.title]}
> > \setMPtext{2}{\usermap[concurrent.location]}
>
> \setMPtext{1}{%
> \xmlatt {\getvariable {div} {concurrent} {title}%
> }
>
> > I can verify the attribute values exist by exporting them to the
> document:
> something like that .. untested as no mwe
>
> 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 /
> https://www.ntg.nl/mailman/listinfo/ntg-context
> webpage : https://www.pragma-ade.nl / http://context.aanhet.net
> archive : https://bitbucket.org/phg/context-mirror/commits/
> wiki : https://contextgarden.net
>
> ___________________________________________________________________________________
>
[-- Attachment #1.2: Type: text/html, Size: 3899 bytes --]
[-- Attachment #2: Type: text/plain, Size: 495 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* [NTG-context] Re: Map XML attributes to variables, dynamically
2023-08-10 8:14 ` Thangalin
@ 2023-08-10 8:37 ` Hans Hagen
2023-08-10 8:50 ` Hans Hagen via ntg-context
0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen @ 2023-08-10 8:37 UTC (permalink / raw)
To: ntg-context
On 8/10/2023 10:14 AM, Thangalin wrote:
> Here's an MWE:
>
> % SOT
> \startbuffer[demo]
> <html>
> <body>
> <div class="concurrent" data-title="Berth 5" data-location="San Diego">
> Text Goes Here
> </div>
> <div class="concurrent" data-title="Road" data-location="Beale AFB">
> Different Text Goes Here
> </div>
> </body>
> </html>
> \stopbuffer
>
> \startxmlsetups xml:xhtml
> \xmlsetsetup{\xmldocument}{*}{-}
> \xmlsetsetup{\xmldocument}{html|body}{xml:*}
> \xmlsetsetup{\xmldocument}{div}{xml:*}
> \stopxmlsetups
>
> \xmlregistersetup{xml:xhtml}
>
> \startxmlsetups xml:html
> \xmlflush{#1}
> \stopxmlsetups
>
> \startxmlsetups xml:body
> \xmlflush{#1}
> \stopxmlsetups
>
> \startxmlsetups xml:div
> \setvariable{div}{\xmlatt{#1}{class}}{#1}
> \start[\xmlatt{#1}{class}]\xmlflush{#1}\stop
> \stopxmlsetups
>
> \definestartstop[concurrent][
> before={TITLE: \xmlatt{\getvariable {div} {concurrent} {title}}},
> ]
>
> \starttext
> \xmlprocessbuffer{main}{demo}{}
> \stoptext
> % EOT
>
> It doesn't look like the variables are taking, regardless of whether
> {title} or {data-title} are used.
\startxmlsetups xml:div
\setvariable{div}{\xmlatt{#1}{class}}{#1}
\start[\xmlatt{#1}{class}]\xmlflush{#1}\stop
\stopxmlsetups
\definestartstop
[concurrent]
[before={TITLE: \xmlatt{\getvariable{div}{concurrent}}{data-title}}]
-- watch the braces
-- use data-title and not title
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 / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* [NTG-context] Re: Map XML attributes to variables, dynamically
2023-08-10 8:37 ` Hans Hagen
@ 2023-08-10 8:50 ` Hans Hagen via ntg-context
2023-08-10 8:55 ` Hans Hagen via ntg-context
0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen via ntg-context @ 2023-08-10 8:50 UTC (permalink / raw)
To: ntg-context; +Cc: Hans Hagen
On 8/10/2023 10:37 AM, Hans Hagen wrote:
> On 8/10/2023 10:14 AM, Thangalin wrote:
>> Here's an MWE:
>>
>> % SOT
>> \startbuffer[demo]
>> <html>
>> <body>
>> <div class="concurrent" data-title="Berth 5" data-location="San Diego">
>> Text Goes Here
>> </div>
>> <div class="concurrent" data-title="Road" data-location="Beale AFB">
>> Different Text Goes Here
>> </div>
>> </body>
>> </html>
>> \stopbuffer
>>
>> \startxmlsetups xml:xhtml
>> \xmlsetsetup{\xmldocument}{*}{-}
>> \xmlsetsetup{\xmldocument}{html|body}{xml:*}
>> \xmlsetsetup{\xmldocument}{div}{xml:*}
>> \stopxmlsetups
>>
>> \xmlregistersetup{xml:xhtml}
>>
>> \startxmlsetups xml:html
>> \xmlflush{#1}
>> \stopxmlsetups
>>
>> \startxmlsetups xml:body
>> \xmlflush{#1}
>> \stopxmlsetups
>>
>> \startxmlsetups xml:div
>> \setvariable{div}{\xmlatt{#1}{class}}{#1}
>> \start[\xmlatt{#1}{class}]\xmlflush{#1}\stop
>> \stopxmlsetups
>>
>> \definestartstop[concurrent][
>> before={TITLE: \xmlatt{\getvariable {div} {concurrent} {title}}},
>> ]
>>
>> \starttext
>> \xmlprocessbuffer{main}{demo}{}
>> \stoptext
>> % EOT
>>
>> It doesn't look like the variables are taking, regardless of whether
>> {title} or {data-title} are used.
>
> \startxmlsetups xml:div
> \setvariable{div}{\xmlatt{#1}{class}}{#1}
> \start[\xmlatt{#1}{class}]\xmlflush{#1}\stop
> \stopxmlsetups
>
> \definestartstop
> [concurrent]
> [before={TITLE: \xmlatt{\getvariable{div}{concurrent}}{data-title}}]
>
> -- watch the braces
> -- use data-title and not title
>
> Hans
You can actually do this:
\startxmlsetups xml:div
\setupstartstop
[\xmlatt{#1}{class}]
[before={TITLE: \xmlatt{#1}{data-title}}]%
\start[\xmlatt{#1}{class}]%
\xmlflush{#1}
\stop
\stopxmlsetups
\definestartstop
[concurrent]
and you then can also do
\namedstartstopparameter{concurrent}{before}
when needed, which save you the intermediate variable because it's
already in before, so from that it's a natural step to
\startxmlsetups xml:div
\setupstartstop
[\xmlatt{#1}{class}]
[title=\xmlatt{#1}{data-title},
before={TITLE: \namedstartstopparameter{concurrent}{title}}]%
\start[\xmlatt{#1}{class}]%
\xmlflush{#1}
\stop
\stopxmlsetups
\definestartstop
[concurrent]
and then with:
\namedstartstopparameter{concurrent}{title}
(i'll add this example to the test suite as demo)
-----------------------------------------------------------------
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 / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* [NTG-context] Re: Map XML attributes to variables, dynamically
2023-08-10 8:50 ` Hans Hagen via ntg-context
@ 2023-08-10 8:55 ` Hans Hagen via ntg-context
0 siblings, 0 replies; 6+ messages in thread
From: Hans Hagen via ntg-context @ 2023-08-10 8:55 UTC (permalink / raw)
To: Hans Hagen via ntg-context; +Cc: Hans Hagen
[-- Attachment #1: Type: text/plain, Size: 529 bytes --]
On 8/10/2023 10:50 AM, Hans Hagen via ntg-context wrote:
> On 8/10/2023 10:37 AM, Hans Hagen wrote:
>> On 8/10/2023 10:14 AM, Thangalin wrote:
>>> Here's an MWE:
attached the more final version
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
[-- Attachment #2: variables-001.tex --]
[-- Type: text/plain, Size: 1178 bytes --]
% follow up on mail discussion with T
\startbuffer[demo]
<html>
<body>
<div class="concurrent" data-title="Berth 5" data-location="San Diego">
Text Goes Here
</div>
<div class="concurrent" data-title="Road" data-location="Beale AFB">
Different Text Goes Here
</div>
</body>
</html>
\stopbuffer
\startxmlsetups xml:xhtml
\xmlsetsetup{\xmldocument}{*}{-}
\xmlsetsetup{\xmldocument}{html|body|div}{xml:*}
\stopxmlsetups
\xmlregistersetup{xml:xhtml}
\startxmlsetups xml:html
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:body
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:div
\setupstartstop
[\xmlatt{#1}{class}]
[title=\xmlatt{#1}{data-title}]%
\start[\xmlatt{#1}{class}]%
\xmlflush{#1}
\stop
\blank
used wherever needed: \namedstartstopparameter{concurrent}{title}
\blank
\stopxmlsetups
\definestartstop
[concurrent]
[before=\startsection[title={TITLE: \namedstartstopparameter{concurrent}{title}}],
after=\stopsection]%
\starttext
\xmlprocessbuffer{main}{demo}{}
\stoptext
[-- Attachment #3: Type: text/plain, Size: 495 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-08-10 8:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-10 7:10 [NTG-context] Map XML attributes to variables, dynamically Thangalin
2023-08-10 7:43 ` [NTG-context] " Hans Hagen
2023-08-10 8:14 ` Thangalin
2023-08-10 8:37 ` Hans Hagen
2023-08-10 8:50 ` Hans Hagen via ntg-context
2023-08-10 8:55 ` Hans Hagen via ntg-context
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).