getting inside xhtml / mkii
Hello, I want to process have a rather complicated xhtml file with dictionary data containing lots of entries like: <span class="word" lang="nld">papa</span> <span class="defenition" lang="en"> <span class="xlanguagetag" lang="en">Eng </span> daddy</span> I tried to write some code to get the individual data elements into my ConTeXt-module, but I didn't succeed. This: \defineXMLargument [span class="word"]{\Mywordstyle{\XMLvar{class="word"}{}}} for example fails, it gives all the data within all the different span's, whereas I want to select the different data items using the
Jelle Huisman wrote:
Hello,
I want to process have a rather complicated xhtml file with dictionary data containing lots of entries like:
<span class="word" lang="nld">papa</span> <span class="defenition" lang="en"> <span class="xlanguagetag" lang="en">Eng </span> daddy</span>
I tried to write some code to get the individual data elements into my ConTeXt-module, but I didn't succeed. This:
\defineXMLargument [span class="word"]{\Mywordstyle{\XMLvar{class="word"}{}}}
\defineXMLargument [span] [class=word] {\Mywordstyle{\XMLpar{span}{class}{default-value}}}
for example fails, it gives all the data within all the different span's, whereas I want to select the different data items using the
consider switching to context mkiv which gives access to the xml tree ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
<span class="word" lang="nld">papa</span>
Thanks Hans, but for this bit of data: this code:
\defineXMLargument [span] [class=word] {\Mywordstyle{\XMLpar{span}{class}{default-value}}}
consider switching to context mkiv which gives access to the xml tree I consider doing this for a future project, but I can't do that for this
applies the \Mywordstyle to the class attribute "word", whereas I'm looking for a solution that applies the style to the word included in the span element, nl. "papa", and it shouldn't print the attribute 'word' at all... (maybe my question wasn't clear the first time.) project since I need to use XeTeX for Graphite enabled fonts. Thanks, Jelle
On Fri, May 9, 2008 at 10:59 AM, Jelle Huisman
<span class="word" lang="nld">papa</span>
Thanks Hans, but for this bit of data: this code:
\defineXMLargument [span] [class=word] {\Mywordstyle{\XMLpar{span}{class}{default-value}}}
consider switching to context mkiv which gives access to the xml tree I consider doing this for a future project, but I can't do that for this
applies the \Mywordstyle to the class attribute "word", whereas I'm looking for a solution that applies the style to the word included in the span element, nl. "papa", and it shouldn't print the attribute 'word' at all... (maybe my question wasn't clear the first time.) project since I need to use XeTeX for Graphite enabled fonts.
Did this come closer to what you want. \defineXMLenvironment [span] [class=] {\bgroup \processaction [\XMLpar{span}{class}{}] [word=>\let\FormatSpan\bold, defenition=>\let\FormatSpan\mono]% \FormatSpan} {\egroup} \starttext \startXMLdata <span class="word" lang="nld">papa</span> <span class="defenition" lang="en"> <span class="xlanguagetag" lang="en">Eng</span> daddy </span> \stopXMLdata \stoptext You should give us more information too help you, how is \Mywordstyle defined because \defineXMLargument can't be nested. Wolfgang
Wolfgang Schuster wrote:
Did this come closer to what you want.
Almost, however I added "xlanguagetag=>\let\FormatSpan\bold" to get to the nested span element and that didn't work. Any suggestions?
\defineXMLenvironment [span] [class=] {\bgroup \processaction [\XMLpar{span}{class}{}] [word=>\let\FormatSpan\bold, defenition=>\let\FormatSpan\mono]%
xlanguagetag=>\let\FormatSpan\bold % <- this does not work (because it is nested?)
\FormatSpan} {\egroup}
\starttext
\startXMLdata <span class="word" lang="nld">papa</span> <span class="defenition" lang="en"> <span class="xlanguagetag" lang="en">Eng</span> daddy </span> \stopXMLdata
\stoptext
You should give us more information too help you, how is \Mywordstyle defined because \defineXMLargument can't be nested. \Mywordstyle is a font switch: \def\Mywordstyle #1{\switchtobodyfont[GentiumItalics] #1\switchtobodyfont[Gentium]}
Thanks again, Jelle
On Fri, May 9, 2008 at 11:56 AM, Jelle Huisman
Wolfgang Schuster wrote:
Did this come closer to what you want.
Almost, however I added "xlanguagetag=>\let\FormatSpan\bold" to get to the nested span element and that didn't work. Any suggestions?
\defineXMLenvironment [span] [class=] {\bgroup \processaction [\XMLpar{span}{class}{}] [word=>\let\FormatSpan\bold, defenition=>\let\FormatSpan\mono]%
xlanguagetag=>\let\FormatSpan\bold % <- this does not work (because it is nested?)
\FormatSpan} {\egroup}
\defineXMLenvironment [span] [class=] {\bgroup \processaction [\XMLpar{span}{class}{}] [word=>\let\FormatSpan\bold, defenition=>\let\FormatSpan\mono, xlanguagetag=>\let\FormatSpan\italic]% \FormatSpan} {\egroup}
\starttext
\startXMLdata <span class="word" lang="nld">papa</span> <span class="defenition" lang="en"> <span class="xlanguagetag" lang="en">Eng</span> daddy </span> \stopXMLdata
\stoptext
You should give us more information too help you, how is \Mywordstyle defined because \defineXMLargument can't be nested.
\Mywordstyle is a font switch: \def\Mywordstyle #1{\switchtobodyfont[GentiumItalics] #1\switchtobodyfont[Gentium]}
Do you really want a font switch, isn't a style switch enough in your case from roman to italic and back. Wolfgang
Wolfgang Schuster wrote:
\Mywordstyle is a font switch: \def\Mywordstyle #1 {\switchtobodyfont[GentiumItalics]{#1} \switchtobodyfont[Gentium]}
Do you really want a font switch, isn't a style switch enough in your case from roman to italic and back. Since I also need to be able to switch to a Non-Roman script I do need a font switch here (that's also the reason why I use XeTeX and MKII.) Anyway when I use \Mywordstyle inside the FormatSpan like this:
[\XMLpar{span}{class}{}] [word=>\let\FormatSpan\Mywordstyle, defenition=>\let\FormatSpan\Mywordstyle, xlanguagetag=>\let\FormatSpan\Mywordstyle]% the font change is applied to the "word" and "xlanguagetag"-items, but not to the definition-item!?(see attachment) Any idea why and how to solve this? (And it looks like there is some unwanted extra space inserted between the "word" and "xlanguagetag" as well.) Jelle
On Fri, May 9, 2008 at 2:53 PM, Jelle Huisman
Wolfgang Schuster wrote:
\Mywordstyle is a font switch: \def\Mywordstyle #1 {\switchtobodyfont[GentiumItalics]{#1} \switchtobodyfont[Gentium]}
Do you really want a font switch, isn't a style switch enough in your case from roman to italic and back.
Since I also need to be able to switch to a Non-Roman script I do need a font switch here (that's also the reason why I use XeTeX and MKII.) Anyway when I use \Mywordstyle inside the FormatSpan like this:
[\XMLpar{span}{class}{}] [word=>\let\FormatSpan\Mywordstyle, defenition=>\let\FormatSpan\Mywordstyle, xlanguagetag=>\let\FormatSpan\Mywordstyle]%
the font change is applied to the "word" and "xlanguagetag"-items, but not to the definition-item!?(see attachment) Any idea why and how to solve this? (And it looks like there is some unwanted extra space inserted between the "word" and "xlanguagetag" as well.)
You could also switch between different typescripts. If you really want to relly on \switchtobodyfont use it inside of a group because the font switch will be local to the group and you go back to the global font after the group. \usetypescript[palatino,times] \setupbodyfont[palatino] \defineXMLenvironment [span] [class=] {\bgroup \processaction [\XMLpar{span}{class}{}] [word=>\let\FormatSpan\italic, defenition=>\let\FormatSpan\bold, xlanguagetag=>\def\FormatSpan{\switchtotypeface[times]}]% \FormatSpan} {\egroup} \starttext \startXMLdata <span class="word" lang="nld">papa</span> <span class="defenition" lang="en"> <span class="xlanguagetag" lang="en">Eng</span> daddy </span> \stopXMLdata \stoptext Wolfgang
Wolfgang Schuster wrote:
You could also switch between different typescripts. If you really want to relly on \switchtobodyfont use it inside of a group because the font switch will be local to the group and you go back to the global font after the group. Thanks Wolfgang, I'll try the typescripts approach.
Jelle
Wolfgang Schuster wrote:
On Fri, May 9, 2008 at 11:56 AM, Jelle Huisman
wrote: Wolfgang Schuster wrote:
Did this come closer to what you want.
Almost, however I added "xlanguagetag=>\let\FormatSpan\bold" to get to the nested span element and that didn't work. Any suggestions?
\defineXMLenvironment [span] [class=] {\bgroup \processaction [\XMLpar{span}{class}{}] [word=>\let\FormatSpan\bold, defenition=>\let\FormatSpan\mono]%
xlanguagetag=>\let\FormatSpan\bold % <- this does not work (because it is nested?)
\FormatSpan} {\egroup}
\defineXMLenvironment [span] [class=] {\bgroup \processaction [\XMLpar{span}{class}{}] [word=>\let\FormatSpan\bold, defenition=>\let\FormatSpan\mono, xlanguagetag=>\let\FormatSpan\italic]% \FormatSpan} {\egroup}
grep for \XMLmapvalue and \XMLval and so ... faster than processaction ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hi again, I'm working on my xhtml file again but somehow I don't get it... Consider this bit of xml: <body class="dicBody"> <div class="letHead"> <div class="letter">A a</div> I want to pickup the "A a"-bit and put it in a \chapter. I tried a good number of variations like this: \defineXMLargument [div] \chapter{\XMLpar{div}{class="letter"}{}} but this does not work. Any hints to solve (and understand!) this would be appreciated! Thanks, Jelle
On Thu, May 15, 2008 at 1:33 PM, Jelle Huisman
Hi again,
I'm working on my xhtml file again but somehow I don't get it... Consider this bit of xml:
<body class="dicBody"> <div class="letHead"> <div class="letter">A a</div>
I want to pickup the "A a"-bit and put it in a \chapter. I tried a good number of variations like this:
\defineXMLargument [div] \chapter{\XMLpar{div}{class="letter"}{}}
but this does not work. Any hints to solve (and understand!) this would be appreciated! Thanks,
You're misusing the div element for something it is not meant, could you use h1 ... elements in your html and map them to ConTeXt's own header commands. Wolfgang
Wolfgang Schuster wrote:
You're misusing the div element for something it is not meant, could you use h1 ... elements in your html and map them to ConTeXt's own header commands. Yes, I know that the xhtml is not very nice (if only I could write my own xml...) The situation is that I get this file from a customer and I want to avoid having to reformat it (for compatibility reasons). That's why I try to make it work, but it seems I'm out of luck here... :-(
Jelle
On Thu, May 15, 2008 at 3:27 PM, Jelle Huisman
Wolfgang Schuster wrote:
You're misusing the div element for something it is not meant, could you use h1 ... elements in your html and map them to ConTeXt's own header commands.
Yes, I know that the xhtml is not very nice (if only I could write my own xml...) The situation is that I get this file from a customer and I want to avoid having to reformat it (for compatibility reasons). That's why I try to make it work, but it seems I'm out of luck here... :-(
It's not impossible but a pain to achive with MkII, I made a example but it did not really woth because the XML-Environment for div is overloaded with the first chapter and you will loose the selection dependent on the value for class. \defineXMLenvironment [div] [class=] {%\bgroup \processaction [\XMLpar{div}{class}{}] [letHead=>\def\next{\defineXMLargument[div]{\chapter}}]% \next} {%\egroup } \starttext \startXMLdata <body class="dicBody"> <div class="letHead"> <div class="letter">A a</div> </div> </body> \stopXMLdata \stoptext If you want to do this project you should consider switching to MkIV with it's XML setups, they are more powerfull in this case and sometimes easier to write. Wolfgang
Wolfgang Schuster wrote:
Yes, I know that the xhtml is not very nice (if only I could write my own xml...) The situation is that I get this file from a customer and I want to avoid having to reformat it (for compatibility reasons). That's why I try to make it work, but it seems I'm out of luck here... :-(
It's not impossible but a pain to achive with MkII, It is a pain indeed, I'll try and see if I can reformat the file a bit. Thanks for your comments, they were helpful,
Jelle
On Thu, May 15, 2008 at 9:54 PM, Jelle Huisman
Yes, I know that the xhtml is not very nice (if only I could write my own xml...) The situation is that I get this file from a customer and I want to avoid having to reformat it (for compatibility reasons). That's why I try to make it work, but it seems I'm out of luck here... :-(
It's not impossible but a pain to achive with MkII,
It is a pain indeed, I'll try and see if I can reformat the file a bit. Thanks for your comments, they were helpful,
You should be switch to MkIV if possible, it is easier to select the elements and you don't need different commands for normal div elements as environments or as commands. Wolfgang
You should be switch to MkIV if possible, it is easier to select the elements and you don't need different commands for normal div elements as environments or as commands. Problem is that I have to use XeTeX for some special fonts, so I have to stay with MkII for this project. (Unless there is a way to mix MkII and MkIV that would allow me to use the MkIV xml handling together with the MkII/XeTeX back end. I guess that would involve using MkIV (at least for
Wolfgang Schuster wrote: the xml bit) but shipping the pages to XeTeX rather then to luaTeX. Which is not possible, as far as I know...) Jelle
On Fri, May 16, 2008 at 12:19 PM, Jelle Huisman
Wolfgang Schuster wrote:
You should be switch to MkIV if possible, it is easier to select the elements and you don't need different commands for normal div elements as environments or as commands.
Problem is that I have to use XeTeX for some special fonts, so I have to stay with MkII for this project. (Unless there is a way to mix MkII and MkIV that would allow me to use the MkIV xml handling together with the MkII/XeTeX back end. I guess that would involve using MkIV (at least for the xml bit) but shipping the pages to XeTeX rather then to luaTeX. Which is not possible, as far as I know...)
What special fonts or features do you use with XeTeX which are not possible with LuaTeX. Wolfgang
Wolfgang Schuster wrote:
What special fonts or features do you use with XeTeX which are not possible with LuaTeX. I need to support Graphite enabled fonts for the rendering of complex non-roman scripts [1], Graphite can currently only be used with XeTeX. Anyway, I'll reformat my source file to something more readable in MkII. In the meantime I'm still interested in ways to mix MkIV xml-support into MkII usage or to output from MkIV to XeTeX.
Jelle [1] http://scripts.sil.org/RenderingGraphite
participants (3)
-
Hans Hagen
-
Jelle Huisman
-
Wolfgang Schuster