From: Thangalin via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Thangalin <thangalin@gmail.com>
Subject: Dynamic document variables from metadata
Date: Sat, 1 Jan 2022 17:54:19 -0800 [thread overview]
Message-ID: <CAANrE7rWY5SCSazHYPxOX6+KOJfgHag4ZFUHvoeMTAkmZW416A@mail.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 1643 bytes --]
Happy New Year!
How would you implement a mechanism that takes arbitrary XHTML <meta> tags
and produces document variables? Consider:
<meta name="journal" content="Nature" />
After running XML setups, the following would write "Nature":
\documentvariable{journal}
The tricky part is doing this without pre-defining them. Here's a short,
self-contained example to help demonstrate:
\startbuffer[xdoc]
<html>
<head>
<meta content="Milena Marić Einstein" name="author"/>
<meta content="Annalen der Physik" name="journal"/>
</head>
<body>
</body>
</html>\stopbuffer
\startxmlsetups xml:xhtml
\xmlsetsetup{\xmldocument}{*}{-}
\xmlsetsetup{\xmldocument}{html|body}{xml:*}
\xmlsetsetup{\xmldocument}{head}{xml:meta}\stopxmlsetups
\xmlregistersetup{xml:xhtml}
\startxmlsetups xml:html
% "author" is a special setup, not generalized
\xmlfilter{#1}{/head/meta[@name='author']/command(xml:author)}
% What goes here to make this dynamic?
%\xmlfilter{#1}{/head/meta[@name='journal']/command(xml:journal)}
\xmlflush{#1}\stopxmlsetups
\startxmlsetups xml:author
\setupdocument[author={\xmlatt{#1}{content}}]
\setupdocument[metadata:author={\xmlatt{#1}{content}}]
\setupinteraction[author={\documentvariable{author}}]\stopxmlsetups
% How can this be generalized?%\startxmlsetups xml:journal
%\setupdocument[journal={\xmlatt{#1}{content}}]%\stopxmlsetups
\startxmlsetups xml:body
\startdocument
Author: \documentvariable{author}
\par
Journal: \documentvariable{journal}
\stopdocument\stopxmlsetups
\xmlprocessbuffer{main}{xdoc}{}
Thank you!
[-- Attachment #1.2: Type: text/html, Size: 3516 bytes --]
[-- Attachment #2: Type: text/plain, Size: 493 bytes --]
___________________________________________________________________________________
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 reply other threads:[~2022-01-02 1:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-02 1:54 Thangalin via ntg-context [this message]
2022-01-02 11:11 ` Hans Hagen via ntg-context
2022-01-02 19:15 ` Thangalin via ntg-context
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=CAANrE7rWY5SCSazHYPxOX6+KOJfgHag4ZFUHvoeMTAkmZW416A@mail.gmail.com \
--to=ntg-context@ntg.nl \
--cc=thangalin@gmail.com \
/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).