ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* XML processing
@ 2002-08-26 11:33 Robbie Pickering
  2002-08-26 14:40 ` Hans Hagen
  2002-08-26 18:53 ` Simon Pepping
  0 siblings, 2 replies; 11+ messages in thread
From: Robbie Pickering @ 2002-08-26 11:33 UTC (permalink / raw)


OK, I'm stymied here.

What i'm trying to do is typeset a dictionary entry from XML. It's
relatively simple so far. But there are occasions when I'd like to have
the same tags treated differently according to the context.

We have for example definitions DEFN which are sometimes followed by an
example EGPH and sometimes not.

...
<DNUM>3</DNUM>
<DEFN>a large body, esp. of a person</DEFN>
<EGPH>he eased his bulk out of the chair</EGPH>
<DNUM>4</DNUM>
<DEFN>unpackaged cargo or goods</DEFN>

I have setup DEFN very simply

\defineXMLenvironment [DEFN] {}{.}  
to add a full stop after the definition. It would be nice, though, to be
able to automatically add a colon instead in those cases where the DEFN
environment is immediately followed by a EGPH.

is the XML parsing code robust enough that one could start messing
around with counters, etc. in the arguments of a \defineXMLenvironment?
Or is there a better way of going about this?


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: XML processing
  2002-08-26 11:33 XML processing Robbie Pickering
@ 2002-08-26 14:40 ` Hans Hagen
  2002-08-26 18:53 ` Simon Pepping
  1 sibling, 0 replies; 11+ messages in thread
From: Hans Hagen @ 2002-08-26 14:40 UTC (permalink / raw)
  Cc: ntg-context

At 12:33 PM 8/26/2002 +0100, Robbie Pickering wrote:
>OK, I'm stymied here.
>
>What i'm trying to do is typeset a dictionary entry from XML. It's
>relatively simple so far. But there are occasions when I'd like to have
>the same tags treated differently according to the context.

Maybe you can use:

\startXMLmapping [local]

\defineXMLenvironment [whatever] {[} {]}

\stopXMLmapping

\defineXMLenvironment [whatever] {(} {)}

\defineXMLenvironment [test]
   {\startXMLmapping[local]}
   {\stopXMLmapping}

\startbuffer
Let's see <whatever>how</whatever> a <test><whatever>how
some nested</whatever></test> text comes out.
\stopbuffer

\starttext \processXMLbuffer \stoptext

Alternaively you can use grouping and locally redefine elements.

>We have for example definitions DEFN which are sometimes followed by an
>example EGPH and sometimes not.
>
>...
><DNUM>3</DNUM>
><DEFN>a large body, esp. of a person</DEFN>
><EGPH>he eased his bulk out of the chair</EGPH>
><DNUM>4</DNUM>
><DEFN>unpackaged cargo or goods</DEFN>
>
>I have setup DEFN very simply
>
>\defineXMLenvironment [DEFN] {}{.}
>to add a full stop after the definition. It would be nice, though, to be
>able to automatically add a colon instead in those cases where the DEFN
>environment is immediately followed by a EGPH.
>
>is the XML parsing code robust enough that one could start messing
>around with counters, etc. in the arguments of a \defineXMLenvironment?
>Or is there a better way of going about this?

what kind of messing?
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                        information: http://www.pragma-ade.com/roadmap.pdf
                     documentation: http://www.pragma-ade.com/showcase.pdf
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: XML processing
  2002-08-26 11:33 XML processing Robbie Pickering
  2002-08-26 14:40 ` Hans Hagen
@ 2002-08-26 18:53 ` Simon Pepping
  2002-08-26 19:25   ` Hans Hagen
  1 sibling, 1 reply; 11+ messages in thread
From: Simon Pepping @ 2002-08-26 18:53 UTC (permalink / raw)


On Mon, Aug 26, 2002 at 12:33:44PM +0100, Robbie Pickering wrote:
> We have for example definitions DEFN which are sometimes followed by an
> example EGPH and sometimes not.
> 
> ...
> <DNUM>3</DNUM>
> <DEFN>a large body, esp. of a person</DEFN>
> <EGPH>he eased his bulk out of the chair</EGPH>
> <DNUM>4</DNUM>
> <DEFN>unpackaged cargo or goods</DEFN>
> 
> I have setup DEFN very simply
> 
> \defineXMLenvironment [DEFN] {}{.}  
> to add a full stop after the definition. It would be nice, though, to be
> able to automatically add a colon instead in those cases where the DEFN
> environment is immediately followed by a EGPH.

This is very difficult, because your tagging has no moment at which
this can be concluded: </DEFN> is too early to know, but when there is
no following EGPH, there is nothing that can trigger the period or
colon. It would be easier if the whole definition would be in a
container: <definition><DNUM/><DEFN/><EGPH/></definition>. Then you
can save EGPH, and </definition> could typeset it with preceding
colon, or it could typeset a period.

> is the XML parsing code robust enough that one could start messing
> around with counters, etc. in the arguments of a \defineXMLenvironment?
> Or is there a better way of going about this?

XML parsing is robust enough. In the docbook mapping a context stack
and a depth counter are maintained. 

Simon

-- 
Simon Pepping
email: spepping@scaprea.hobby.nl


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: XML processing
  2002-08-26 18:53 ` Simon Pepping
@ 2002-08-26 19:25   ` Hans Hagen
  0 siblings, 0 replies; 11+ messages in thread
From: Hans Hagen @ 2002-08-26 19:25 UTC (permalink / raw)
  Cc: ntg-context

At 08:53 PM 8/26/2002 +0200, Simon Pepping wrote:
>On Mon, Aug 26, 2002 at 12:33:44PM +0100, Robbie Pickering wrote:
> > We have for example definitions DEFN which are sometimes followed by an
> > example EGPH and sometimes not.
> >
> > ...
> > <DNUM>3</DNUM>
> > <DEFN>a large body, esp. of a person</DEFN>
> > <EGPH>he eased his bulk out of the chair</EGPH>
> > <DNUM>4</DNUM>
> > <DEFN>unpackaged cargo or goods</DEFN>
> >
> > I have setup DEFN very simply
> >
> > \defineXMLenvironment [DEFN] {}{.}
> > to add a full stop after the definition. It would be nice, though, to be
> > able to automatically add a colon instead in those cases where the DEFN
> > environment is immediately followed by a EGPH.
>
>This is very difficult, because your tagging has no moment at which
>this can be concluded: </DEFN> is too early to know, but when there is
>no following EGPH, there is nothing that can trigger the period or
>colon. It would be easier if the whole definition would be in a
>container: <definition><DNUM/><DEFN/><EGPH/></definition>. Then you
>can save EGPH, and </definition> could typeset it with preceding
>colon, or it could typeset a period.

actually, there is a trick:

say that you add a signal:

\newsignal\MySignal

bla bla\hskip\MySignal

then you can test for this signal:

\ifdim\lastskip\MySignal
   ...
\else
   ...
\fi

so, here EGPH should do the test, and DEFN add the skip

of course a little bit of hmode testing and removing of spaces helps

[if needed i can make a mechanism for that since i use it myself occasionally]

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                        information: http://www.pragma-ade.com/roadmap.pdf
                     documentation: http://www.pragma-ade.com/showcase.pdf
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: xml processing
  2011-12-31 20:55 xml processing Meer, H. van der
@ 2012-01-01 12:14 ` Hans Hagen
  0 siblings, 0 replies; 11+ messages in thread
From: Hans Hagen @ 2012-01-01 12:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 31-12-2011 21:55, Meer, H. van der wrote:
> Is there a macro to retrieve the name of the file when inside a call to \xmlprocessfile?

no, there isn't

-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 11+ messages in thread

* xml processing
@ 2011-12-31 20:55 Meer, H. van der
  2012-01-01 12:14 ` Hans Hagen
  0 siblings, 1 reply; 11+ messages in thread
From: Meer, H. van der @ 2011-12-31 20:55 UTC (permalink / raw)
  To: ConTeXt NTG

Is there a macro to retrieve the name of the file when inside a call to \xmlprocessfile?

Hans van der Meer



___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: XML Processing
  2003-05-21 20:12 ` Johannes Hüsing
@ 2003-05-23 12:46   ` Hans Hagen
  0 siblings, 0 replies; 11+ messages in thread
From: Hans Hagen @ 2003-05-23 12:46 UTC (permalink / raw)


At 22:12 21/05/2003 +0200, you wrote:
>Dear Alexandre,
>
>I am using the following here, using the QUIZIT format for multiple choice
>things.

I have a mpc demo style somehwere which keep track of scores, feedback etc 
in such an xml coded doc (interactively); i'll see if i can wrap that up 
into a style

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                        information: http://www.pragma-ade.com/roadmap.pdf
                     documentation: http://www.pragma-ade.com/showcase.pdf
-------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: XML Processing
  2003-05-20 16:35 XML Processing Alexandre Enkerli
  2003-05-21  8:11 ` Berend de Boer
  2003-05-21 19:56 ` Simon Pepping
@ 2003-05-21 20:12 ` Johannes Hüsing
  2003-05-23 12:46   ` Hans Hagen
  2 siblings, 1 reply; 11+ messages in thread
From: Johannes Hüsing @ 2003-05-21 20:12 UTC (permalink / raw)


Dear Alexandre,

I am using the following here, using the QUIZIT format for multiple choice
things.

Regards


Johannes

\def\abschnitt{\par}

\defineXMLenvironment [P]                              {}{\abschnitt}
\defineXMLargument    [TITLE]                          {\Anschreiben}
\defineXMLargument    [EXAM]                           {\gobble}
\defineXMLenvironment [INSTRUCTION]                    {\startframedtext}{\stopframedtext}
\defineXMLenvironment [QUESTION-GROUP] [id=,next=]     {\subject{\XMLpar{question-group}
                                                                {id}{}}\resetfrage}
                                                       {\par\page[yes]\Refseite}
\defineXMLenvironment [ITEM]                           {\item}{}
\defineXMLenvironment [MCHOICE]                        {\StartMchoice}{\StopMchoice}
\defineXMLenvironment [ANSWER]                         {\StartAnswer}{\StopAnswer}
\defineXMLenvironment [DESCRIPTION]                    {}{\StopDescription}

\definelabel[frage][text=Frage, location=inmargin]
\definelabel[antwort]

\def\StopDescription{\startitemize[a, inmargin, intro]}
\def\StartMchoice{\frage}
\def\StopMchoice{\stopitemize\page[bigpreference]}
\def\StartAnswer{\begingroup\def\abschnitt{\relax} \item }
\def\StopAnswer{\dotfill\inright{\Square}\endgroup\par}
        %{\XMLpar{ANSWER}{VALUE}}\par}
        %\XMLifequalelse{answer}{value}{wrong}{X}{O}}\par}
\def\gobble#1{}


\definemakeup[anschreiben][hoffset=17mm, voffset=50mm]
\definemakeup[refseite][hoffset=17mm, voffset=50mm]

\setuppagenumbering[state=none]

\startreusableMPgraphic{L7}
draw unitsquare scaled 14pt;
\stopreusableMPgraphic

\startuseMPgraphic{crossed}
u := 10pt;
draw unitsquare scaled u;
draw (0u,0u)--(1u,1u);
draw (0u,1u)--(1u,0u);
\stopuseMPgraphic

\startuseMPgraphic{doublecrossed}
u := 10pt;
draw unitsquare scaled u;
draw (0u,0u)--(1u,1u);
draw (0u,1u)--(1u,0u);
draw (0.5u,0u)--(0.5u,1u);
draw (0u,0.5u)--(1u,0.5u);
\stopuseMPgraphic

\def\Square{\reuseMPgraphic{L7}}
\def\Crossed{\reuseMPgraphic{crossed}}
\def\DoubleCrossed{\reuseMPgraphic{doublecrossed}}


\setupoutput[pdf]
\mainlanguage[de]
\useencoding[win]

\def\Anschreiben#1{%
\startanschreibenmakeup
{\tfb #1}\crlf
\vfill
\startitemize
\item Bitte schreiben Sie auf diese Seite Ihren Namen und Ihre
EDV-Nummer.
\item Die Zeit zur Bearbeitung beträgt 45 Minuten.
\item Jede Frage hat fünf Antworten. Nur eine
Antwort ist anzukreuzen.
\item Manche Fragen und Antworten können durch einen Seitenumbruch
unterbrochen sein.
\item Kreuzen Sie das Kästchen zur Antwort diagonal an
(\Crossed). Wenn Sie sich korrigieren möchten, kreuzen Sie es gerade
durch (\DoubleCrossed) und machen Ihr Kreuz in ein anderes Kästchen.
\item Die letzte Seite können Sie als Referenz nutzen, abreißen und behalten.
\stopitemize
\vfill
\stopanschreibenmakeup
\setupheadertexts[][#1]}

\def\Refseite{
\subject{Meine Lösungen}
\startitemize[n, three]
\item
\item
\item
\item
\item
\item
\item
\item
\item
\item
\item
\item
\stopitemize
}

\starttext
\processXMLfilegrouped{KlausurW2003n.xml}
\stoptext




-- 
Johannes Hüsing   There is something fascinating about science. One gets
hannes@ruhrau.de  such wholesale returns of conjecture from such a 
                  trifling investment of fact.                Mark Twain

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: XML Processing
  2003-05-20 16:35 XML Processing Alexandre Enkerli
  2003-05-21  8:11 ` Berend de Boer
@ 2003-05-21 19:56 ` Simon Pepping
  2003-05-21 20:12 ` Johannes Hüsing
  2 siblings, 0 replies; 11+ messages in thread
From: Simon Pepping @ 2003-05-21 19:56 UTC (permalink / raw)


On Tue, May 20, 2003 at 01:35:08PM -0300, Alexandre Enkerli wrote:
> Hello all,
> 
> Here's the basic structure of the data I want to process:
> 	<question>
> 		<text></text>
> 		<choices>
> 			<choice></choice>
> 		</choices>
> 		<answer></answer>
> 		<info>
> 			<difficulty></difficulty>
> 			<reference></reference>
> 			<text-objective></text-objective>
> 		</info>
> 	</question>
> 
> In LaTeX terminology (sorry!) what I want is to have all the question 
> texts as items in an "enumerate" and answer choices in an alphabetical 
> enumerate for each question. Doesn't sound too hard. In fact, I guess I 
> could probably do a find and replace...

You should write proper callbacks for each element:

\defineXMLenvironment[text]
	{start action}
	{stop action}

It is easy if you want the text of the query italic with a 'Q.' before
it:

\defineXMLenvironment[text]
	{\bgroup Q. \bf}
	{\egroup}

You can also easily start a list:

\defineXMLenvironment[choices]
	{\startitemize}
	{\stopitemize}
\defineXMLcommand[choice]
	{\item}

But collecting all queries together and all answers together, or
sorting the choices alphabetically, sounds pretty hard. You would have
to save them all in appropriate data structures, and then print them
out as desired. The context code has examples which show that this can
be done in TeX macro code, but it is certainly not easy. As per
Berend's suggestion, XSLT is a much better tool for this task. Then
write a context mapping for the properly sorted XML file.

Good luck, Simon

-- 
Simon Pepping
email: spepping@scaprea.hobby.nl

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: XML Processing
  2003-05-20 16:35 XML Processing Alexandre Enkerli
@ 2003-05-21  8:11 ` Berend de Boer
  2003-05-21 19:56 ` Simon Pepping
  2003-05-21 20:12 ` Johannes Hüsing
  2 siblings, 0 replies; 11+ messages in thread
From: Berend de Boer @ 2003-05-21  8:11 UTC (permalink / raw)


Alexandre Enkerli <aenkerli@indiana.edu> writes:

> In LaTeX terminology (sorry!) what I want is to have all the question
> texts as items in an "enumerate" and answer choices in an alphabetical
> enumerate for each question. Doesn't sound too hard. In fact, I guess
> I could probably do a find and replace...

If you want to sort things, it might be easier to preprocess things or
generate things with an XSLT processor.

-- 
Live long and prosper,

Berend de Boer

^ permalink raw reply	[flat|nested] 11+ messages in thread

* XML Processing
@ 2003-05-20 16:35 Alexandre Enkerli
  2003-05-21  8:11 ` Berend de Boer
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Alexandre Enkerli @ 2003-05-20 16:35 UTC (permalink / raw)


Hello all,
I'm building an exam using "ExamView Pro" which has, surprisingly, an 
XML export feature. I'd like to process the exam content into ConTeXt. 
I've looked at the "Example" file and tried to understand how it all 
works, but I'm not sure I can. So far, I've been able to process 
entities and MathML using the mm* and ent as options for --xmlfilter 
(texexec --pdf --xmlfilter=mml,mmp,mmc,ent file.xml) but I can't even 
get <b> to work as planned with any of the xtag-* files. I'm guessing I 
need to use the x-contml.tex file, but I don't know why.
Then, I'll probably need some guidance to have everything work.
The ExamView XML format uses attributes but I'd be happy with just 
getting the basic format straight.
What makes it somewhat harder is that I don't have so much experience 
with ConTeXt anyway.
So, I'd appreciate any help.

Here's the basic structure of the data I want to process:
	<question>
		<text></text>
		<choices>
			<choice></choice>
		</choices>
		<answer></answer>
		<info>
			<difficulty></difficulty>
			<reference></reference>
			<text-objective></text-objective>
		</info>
	</question>

In LaTeX terminology (sorry!) what I want is to have all the question 
texts as items in an "enumerate" and answer choices in an alphabetical 
enumerate for each question. Doesn't sound too hard. In fact, I guess I 
could probably do a find and replace...

Thanks in advance for your help.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-01-01 12:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-26 11:33 XML processing Robbie Pickering
2002-08-26 14:40 ` Hans Hagen
2002-08-26 18:53 ` Simon Pepping
2002-08-26 19:25   ` Hans Hagen
2003-05-20 16:35 XML Processing Alexandre Enkerli
2003-05-21  8:11 ` Berend de Boer
2003-05-21 19:56 ` Simon Pepping
2003-05-21 20:12 ` Johannes Hüsing
2003-05-23 12:46   ` Hans Hagen
2011-12-31 20:55 xml processing Meer, H. van der
2012-01-01 12:14 ` Hans Hagen

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).