ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <pragma@wxs.nl>
Subject: Re: xml and buffers
Date: Thu, 19 Jan 2006 17:55:22 +0100	[thread overview]
Message-ID: <43CFC47A.3040209@wxs.nl> (raw)
In-Reply-To: <20060119182329.GB25283@zapata.cryptyx.com>

Junod Antoine wrote:

>Hello gurus, 
>
>I'm a bit into trouble wih buffers and xml parsing. Here is my problem:
>
>I've got a .xhtml with the following lines:
>
>     [...]
>     <meta name="course_name" content="G�nie Logiciel" />
>     <meta name="date" content="23 d�cembre 2005" />
>     [...]
>     <title>Auction: document d'analyse</title>
>     [...]
>
>I'm trying to store the content of the meta tag in a buffer, one per
>meta tag, (ie "G�nie Logiciel" in buffer course_name, "23 d�cembre
>2005" in buffer date) to use these buffers when I meet the title tag:
>
>     \XMLifequalelse{meta}{name}{course_name}
>          {\startbuffer[course_name]\XMLpar{meta}{content}{}\stopbuffer}{}
>     \XMLifequalelse{meta}{name}{date}
>          {\startbuffer[date]\XMLpar{meta}{content}{}\stopbuffer}{}
>     \defineXMLenvironment [title] {\startstandardmakeup
>                                    \getbuffer[course_name]
>                                    \getbuffer[date]}{\stopstandardmakeup}
>
>But it does not print anything else than the title.
>  
>
buffers serve a different purpose and are part if a text flow 

\starttext

\defineXMLsingular
  [meta]
  [name=,content=]
  {\setevariables[document:meta][\XMLop{name}=\XMLop{content}]}

\defineXMLenvironment
  [title]
  {}
  {\startstandardmakeup
       \getvariable{document:meta}{course_name} \endgraf
       \getvariable{document:meta}{date} \endgraf
   \stopstandardmakeup}

\startXMLdata
<meta name="course_name" content="Genie Logiciel"   />
<meta name="date"        content="23 decembre 2005" />

<title/>
\stopXMLdata

With a little extension (i'll add it) we can prevent unwanted expansion: 

\unprotected \def\setvalueXMLpar#1#2#3%
 {\@EA\let\csname#1\@EA\endcsname
    \csname\ifcsname\@@XMLvariable:#2:#3\endcsname
      \@@XMLvariable:#2:#3\else\s!empty\fi\endcsname}

\defineXMLsingular
  [meta]
  [name=,content=]
  {\setvalueXMLpar{document:meta:\XMLop{name}}{meta}{content}}

\defineXMLenvironment
  [title]
  {}
  {\startstandardmakeup
       \getvalue{document:meta:course_name} \endgraf
       \getvalue{document:meta:date} \endgraf
   \stopstandardmakeup}

\startXMLdata
<meta name="course_name" content="Genie Logiciel"   />
<meta name="date"        content="23 decembre 2005" />

<title/>
\stopXMLdata


\stoptext

  reply	other threads:[~2006-01-19 16:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-19 18:23 Junod Antoine
2006-01-19 16:55 ` Hans Hagen [this message]
2006-01-20  7:28   ` Junod Antoine
2006-01-20 19:33   ` Junod Antoine

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=43CFC47A.3040209@wxs.nl \
    --to=pragma@wxs.nl \
    --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).