ConTeXt, XML, multiple attributes evaluation
Hello again, Another one: I'm trying to expand
\defineXMLenvironment [list]% {% \expanded{% \startitemize% [% \XMLifequalelse{list}{packed}{yes}{packed}{unpacked}% ]% }% }% {\stopitemize}
which can deal with things like
<list packed="yes"> <item> </item> </list>
To something able to deal with multiple attributes (a "setup" statement for now):
<list packed="yes" setup="n"> <item> </item> </list>
I have tryed multiple incarnations of
\defineXMLenvironment [list]% {% \expanded{% \startitemize% [% \XMLifequalelse{list}{setup}{n}{n}{},% \XMLifequalelse{list}{packed}{yes}{packed}{unpacked}% ]% }% }% {\stopitemize}
but this doesn't work ... Can anybody give me any pointers here? Thanks for time and help, Joh -- +----------------------------------------------------------------------+ | Johannes Graumann, Dipl. Biol. | | | | Graduate Student Tel.: ++1 (626) 395 6602 | | Deshaies Lab Fax.: ++1 (626) 395 5739 | | Department of Biology | | CALTECH, M/C 156-29 | | 1200 E. California Blvd. | | Pasadena, CA 91125 | | USA | +----------------------------------------------------------------------+
Hello Johannes, I consider your first \XMLifequalelse command a bit strange. This command is intented to be used if you want to convert the attribute values into something else (e.g. "yes" into "packed"). If you need the unmodified parameter value, simply use \XMLpar. So e.g.: \startitemize[ \XMLpar{list}{setup}{}, \XMLifequalelse{list}{packed}{yes}{packed}{unpacked} ] Of course "setup" should be a required attribute of <list> (in your DTD), otherwise it would lead to something like \startitemize[,packed] which obviously wouldn't work at all. If it's not the case, I'd use \doifXMLparelse: \doifXMLparelse{list}{setup}{% \startitemize[ \XMLpar{list}{setup}{}, \XMLifequalelse{list}{packed}{yes}{packed}{unpacked} ]% }{% \startitemize[1, \XMLifequalelse{list}{packed}{yes}{packed}{unpacked} ] } -Richard _____ From: Johannes Graumann [mailto:graumann@caltech.edu] To: ntg-context@ntg.nl Sent: Tue, 29 Nov 2005 05:30:25 +0100 Subject: [NTG-context] ConTeXt, XML, multiple attributes evaluation Hello again, Another one: I'm trying to expand
\defineXMLenvironment [list]% {% \expanded{% \startitemize% [% \XMLifequalelse{list}{packed}{yes}{packed}{unpacked}% ]% }% }% {\stopitemize}
which can deal with things like
<list packed="yes"> <item> </item> </list>
To something able to deal with multiple attributes (a "setup" statement for now):
<list packed="yes" setup="n"> <item> </item> </list>
I have tryed multiple incarnations of
\defineXMLenvironment [list]% {% \expanded{% \startitemize% [% \XMLifequalelse{list}{setup}{n}{n}{},% \XMLifequalelse{list}{packed}{yes}{packed}{unpacked}% ]% }% }% {\stopitemize}
but this doesn't work ... Can anybody give me any pointers here? Thanks for time and help, Joh -- +----------------------------------------------------------------------+ | Johannes Graumann, Dipl. Biol. | | | | Graduate Student Tel.: ++1 (626) 395 6602 | | Deshaies Lab Fax.: ++1 (626) 395 5739 | | Department of Biology | | CALTECH, M/C 156-29 | | 1200 E. California Blvd. | | Pasadena, CA 91125 | | USA | +----------------------------------------------------------------------+ _______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
Richard Gabriel wrote:
Hello Johannes,
I consider your first \XMLifequalelse command a bit strange. This command is intented to be used if you want to convert the attribute values into something else (e.g. "yes" into "packed"). If you need the unmodified parameter value, simply use \XMLpar. So e.g.:
\startitemize[ \XMLpar{list}{setup}{}, \XMLifequalelse{list}{packed}{yes}{packed}{unpacked} ]
Of course "setup" should be a required attribute of <list> (in your DTD), otherwise it would lead to something like \startitemize[,packed] which obviously wouldn't work at all. If it's not the case, I'd use \doifXMLparelse:
\doifXMLparelse{list}{setup}{% \startitemize[ \XMLpar{list}{setup}{}, \XMLifequalelse{list}{packed}{yes}{packed}{unpacked} ]% }{% \startitemize[1, \XMLifequalelse{list}{packed}{yes}{packed}{unpacked} ] }
-Richard
------------------------------------------------------------------------ *From:* Johannes Graumann [mailto:graumann@caltech.edu] *To:* ntg-context@ntg.nl *Sent:* Tue, 29 Nov 2005 05:30:25 +0100 *Subject:* [NTG-context] ConTeXt, XML, multiple attributes evaluation
Hello again,
Another one: I'm trying to expand >\defineXMLenvironment [list]% > {% > \expanded{% > \startitemize% > [% > \XMLifequalelse{list}{packed}{yes}{packed}{unpacked}% > ]% > }% > }% > {\stopitemize}
which can deal with things like ><list packed="yes"> > <item> > </item> ></list>
To something able to deal with multiple attributes (a "setup" statement for now): ><list packed="yes" setup="n"> > <item> > </item> ></list>
I have tryed multiple incarnations of >\defineXMLenvironment [list]% > {% > \expanded{% > \startitemize% > [% > \XMLifequalelse{list}{setup}{n}{n}{},% > \XMLifequalelse{list}{packed}{yes}{packed}{unpacked}% > ]% > }% > }% > {\stopitemize}
but this doesn't work ...
Can anybody give me any pointers here?
a convenient way is to use the remapper: \mapXMLvalue {list:packed} {yes} {packed} \mapXMLvalue {list:packed} {no} {unpacked} and then: \defineXMLenvironment [list] [packed=no] {\startitemize[\XMLval{list:packed}{\XMLop{packed}}{}]} {\stopitemize} no fuzzy testing involved, just expansion (fast and clean) Hans
Thanks, Hans! One's still learning... R. _____ From: Hans Hagen [mailto:pragma@wxs.nl] To: mailing list for ConTeXt users [mailto:ntg-context@ntg.nl] Cc: graumann@its.caltech.edu Sent: Tue, 29 Nov 2005 10:52:14 +0100 Subject: Re: [NTG-context] ConTeXt, XML, multiple attributes evaluation Richard Gabriel wrote:
Hello Johannes,
I consider your first \XMLifequalelse command a bit strange. This command is intented to be used if you want to convert the attribute values into something else (e.g. "yes" into "packed"). If you need the unmodified parameter value, simply use \XMLpar. So e.g.:
\startitemize[ \XMLpar{list}{setup}{}, \XMLifequalelse{list}{packed}{yes}{packed}{unpacked} ]
Of course "setup" should be a required attribute of <list> (in your DTD), otherwise it would lead to something like \startitemize[,packed] which obviously wouldn't work at all. If it's not the case, I'd use \doifXMLparelse:
\doifXMLparelse{list}{setup}{% \startitemize[ \XMLpar{list}{setup}{}, \XMLifequalelse{list}{packed}{yes}{packed}{unpacked} ]% }{% \startitemize[1, \XMLifequalelse{list}{packed}{yes}{packed}{unpacked} ] }
-Richard
------------------------------------------------------------------------ *From:* Johannes Graumann [mailto:graumann@caltech.edu] *To:* ntg-context@ntg.nl *Sent:* Tue, 29 Nov 2005 05:30:25 +0100 *Subject:* [NTG-context] ConTeXt, XML, multiple attributes evaluation
Hello again,
Another one: I'm trying to expand >\defineXMLenvironment [list]% > {% > \expanded{% > \startitemize% > [% > \XMLifequalelse{list}{packed}{yes}{packed}{unpacked}% > ]% > }% > }% > {\stopitemize}
which can deal with things like ><list packed="yes"> > <item> > </item> ></list>
To something able to deal with multiple attributes (a "setup" statement for now): ><list packed="yes" setup="n"> > <item> > </item> ></list>
I have tryed multiple incarnations of >\defineXMLenvironment [list]% > {% > \expanded{% > \startitemize% > [% > \XMLifequalelse{list}{setup}{n}{n}{},% > \XMLifequalelse{list}{packed}{yes}{packed}{unpacked}% > ]% > }% > }% > {\stopitemize}
but this doesn't work ...
Can anybody give me any pointers here?
a convenient way is to use the remapper: \mapXMLvalue {list:packed} {yes} {packed} \mapXMLvalue {list:packed} {no} {unpacked} and then: \defineXMLenvironment [list] [packed=no] {\startitemize[\XMLval{list:packed}{\XMLop{packed}}{}]} {\stopitemize} no fuzzy testing involved, just expansion (fast and clean) Hans _______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
Johannes Graumann wrote:
but this doesn't work ...
But it worked fine for me!? Anyway, it is probably a better idea to do it like this: \defineXMLenvironment [list]% {% \let\listoptions\empty \XMLifequalelse{list}{setup}{n} {\appendtocommalist{n}\listoptions} {}% \XMLifequalelse{list}{packed}{yes} {\appendtocommalist{packed}\listoptions} {\appendtocommalist{unpacked}\listoptions}% \expanded{% \startitemize[\listoptions]% }% }% {\stopitemize} Because that way, the xml attributes can be optional. If it still doesn't work, please explain what goes wrong. Greetings, Taco
but this doesn't work ...
But it worked fine for me!? Well, ... if I actually use the "setup" assignment in the list tag rather
Taco Hoekwater wrote: than an item tag it works for me as well ... ;0)
Anyway, it is probably a better idea to do it like this:
\defineXMLenvironment [list]% {% \let\listoptions\empty \XMLifequalelse{list}{setup}{n} {\appendtocommalist{n}\listoptions} {}% \XMLifequalelse{list}{packed}{yes} {\appendtocommalist{packed}\listoptions} {\appendtocommalist{unpacked}\listoptions}% \expanded{% \startitemize[\listoptions]% }% }% {\stopitemize}
Because that way, the xml attributes can be optional. If it still doesn't work, please explain what goes wrong. Thanks so mutch for this! Do you see any way of generalizing the "XMLifequalelse{list}{setup}{n}" part? Could I just have the argument of "<list setup="whatever">" handed thtough to ConTeXt rather than writing if-loops for n,a,A,KA,r,R,KR,m,g,G,1,2,3,4,5,6,7,8?
Thanks for your help! Joh -- +----------------------------------------------------------------------+ | Johannes Graumann, Dipl. Biol. | | | | Graduate Student Tel.: ++1 (626) 395 6602 | | Deshaies Lab Fax.: ++1 (626) 395 5739 | | Department of Biology | | CALTECH, M/C 156-29 | | 1200 E. California Blvd. | | Pasadena, CA 91125 | | USA | +----------------------------------------------------------------------+
Johannes Graumann wrote:
Thanks so mutch for this! Do you see any way of generalizing the "XMLifequalelse{list}{setup}{n}" part? Could I just have the argument of "<list setup="whatever">" handed thtough to ConTeXt rather than writing if-loops for n,a,A,KA,r,R,KR,m,g,G,1,2,3,4,5,6,7,8?
that's what mapXMLvalue is for Hans
Hans, I'm just not getting it ... can't find the appropriate documentation maybe? http://www.pragma-ade.nl/general/manuals/example.pdf is all I got and e.g. "XMLop" does not show up at all in there ... I tryed to get this working (just trial and error), but I just don't understand ... can you kick me some more into the right direction? \mapXMLvalue {list:packed} {yes} {packed} \mapXMLvalue {list:packed} {no} {unpacked} \mapXMLvalue {list:setup} {\XMLpar{list}{setup}{}} {setup} \defineXMLenvironment [list] [packed=no,setup=1] {% \startitemize[% \XMLval{list:setup}{\XMLop{setup}}{}, \XMLval{list:packed}{\XMLop{packed}}{} ]% }% {\stopitemize} Likly many a thing doesn't make sense at all - I just don't get it. Any hint is highly appreciated, Joh Hans Hagen wrote:
Johannes Graumann wrote:
Thanks so mutch for this! Do you see any way of generalizing the "XMLifequalelse{list}{setup}{n}" part? Could I just have the argument of "<list setup="whatever">" handed thtough to ConTeXt rather than writing if-loops for n,a,A,KA,r,R,KR,m,g,G,1,2,3,4,5,6,7,8?
that's what mapXMLvalue is for
Hans
-- +----------------------------------------------------------------------+ | Johannes Graumann, Dipl. Biol. | | | | Graduate Student Tel.: ++1 (626) 395 6602 | | Deshaies Lab Fax.: ++1 (626) 395 5739 | | Department of Biology | | CALTECH, M/C 156-29 | | 1200 E. California Blvd. | | Pasadena, CA 91125 | | USA | +----------------------------------------------------------------------+
Johannes Graumann wrote:
Hans,
I'm just not getting it ... can't find the appropriate documentation maybe? http://www.pragma-ade.nl/general/manuals/example.pdf is all I got and e.g. "XMLop" does not show up at all in there ...
XMLop{xx} is a shortcut for \XMLpar{list}{xx}{some default} and as long as the current element is list that will work, so \defineXMLenvironment[list] {here \XMLop{xx} works fine} {but here the last element encountered may be another than list}
I tryed to get this working (just trial and error), but I just don't understand ... can you kick me some more into the right direction?
\mapXMLvalue {list:packed} {yes} {packed} \mapXMLvalue {list:packed} {no} {unpacked} \mapXMLvalue {list:setup} {\XMLpar{list}{setup}{}} {setup} \defineXMLenvironment [list] [packed=no,setup=1] {% \startitemize[% \XMLval{list:setup}{\XMLop{setup}}{}, \XMLval{list:packed}{\XMLop{packed}}{} ]% }% {\stopitemize}
Likly many a thing doesn't make sense at all - I just don't get it.
Any hint is highly appreciated,
This works ok here: \mapXMLvalue {list:packed} {yes} {packed} \mapXMLvalue {list:packed} {no} {unpacked} \defineXMLenvironment [list] [packed=no,setup=1] {\startitemize[\XMLop{setup},\XMLval{list:packed}{\XMLop{packed}}{}]} {\stopitemize} \defineXMLenvironment [item] {\item} {\endgraf} \starttext \startXMLdata <list packed='yes'> <item>item one</item> <item>item two</item> </list> \stopXMLdata \startXMLdata <list> <item>item one</item> <item>item two</item> </list> \stopXMLdata \startXMLdata <list packed='yes' setup='a'> <item>item one</item> <item>item two</item> </list> \stopXMLdata \startXMLdata <list setup='a'> <item>item one</item> <item>item two</item> </list> \stopXMLdata \stoptext (it may help to look at the x-* files in the context/base path) Hans
Thanks, Does what I want and opens the door for further exploration ... Joh Hans Hagen wrote:
Johannes Graumann wrote:
Hans,
I'm just not getting it ... can't find the appropriate documentation maybe? http://www.pragma-ade.nl/general/manuals/example.pdf is all I got and e.g. "XMLop" does not show up at all in there ...
XMLop{xx} is a shortcut for \XMLpar{list}{xx}{some default}
and as long as the current element is list that will work, so
\defineXMLenvironment[list] {here \XMLop{xx} works fine} {but here the last element encountered may be another than list}
I tryed to get this working (just trial and error), but I just don't understand ... can you kick me some more into the right direction?
\mapXMLvalue {list:packed} {yes} {packed} \mapXMLvalue {list:packed} {no} {unpacked} \mapXMLvalue {list:setup} {\XMLpar{list}{setup}{}} {setup} \defineXMLenvironment [list] [packed=no,setup=1] {% \startitemize[% \XMLval{list:setup}{\XMLop{setup}}{}, \XMLval{list:packed}{\XMLop{packed}}{} ]% }% {\stopitemize}
Likly many a thing doesn't make sense at all - I just don't get it.
Any hint is highly appreciated,
This works ok here:
\mapXMLvalue {list:packed} {yes} {packed} \mapXMLvalue {list:packed} {no} {unpacked}
\defineXMLenvironment [list] [packed=no,setup=1] {\startitemize[\XMLop{setup},\XMLval{list:packed}{\XMLop{packed}}{}]} {\stopitemize}
\defineXMLenvironment [item] {\item} {\endgraf}
\starttext
\startXMLdata <list packed='yes'> <item>item one</item> <item>item two</item> </list> \stopXMLdata
\startXMLdata <list> <item>item one</item> <item>item two</item> </list> \stopXMLdata
\startXMLdata <list packed='yes' setup='a'> <item>item one</item> <item>item two</item> </list> \stopXMLdata
\startXMLdata <list setup='a'> <item>item one</item> <item>item two</item> </list> \stopXMLdata
\stoptext
(it may help to look at the x-* files in the context/base path)
Hans
-- +----------------------------------------------------------------------+ | Johannes Graumann, Dipl. Biol. | | | | Graduate Student Tel.: ++1 (626) 395 6602 | | Deshaies Lab Fax.: ++1 (626) 395 5739 | | Department of Biology | | CALTECH, M/C 156-29 | | 1200 E. California Blvd. | | Pasadena, CA 91125 | | USA | +----------------------------------------------------------------------+
participants (4)
-
Hans Hagen
-
Johannes Graumann
-
Richard Gabriel
-
Taco Hoekwater