Re: [NTG-context] xml attribute conditional
Hans, Thanks for this. It's almost what I need. I truly appreciate the effort, and it does give me some ideas about things to try. However, if I change your example buffer slightly (for clarity) to this: arab foo arab bar english eggs english ham note text ONE note text TWO your code runs and gives me this: [div a] arab [footnote1] arab [footnote2] [div a] [div b] english [note1 eggs ] english [note2 ham ] [div b] 1 foo 2 bar but what I'm trying for is this: [div a] arab [ foo1 ] arab [ bar2 ] [div a] [div b] english [ eggs1 ] english [ ham2 ] [div b] 1 note text ONE 2 note text TWO ___ 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 ___
Re: [NTG-context] xml attribute conditional
On 14-12-2011 19:33, Jon Crump wrote: @xml:id==string.sub('#N020-18', 2) -> (ll.at and ll.at['xml:id'])==string.sub('#N020-18', 2) ! Missing number, treated as zero. lua error with sub .. not sure what you want t o test here indeed an error will prevent the multipass file to be saved (feature) Hans Thanks Hans, It's good to know the --result problem is not a bug, but a feature. My problem then arises from my use of \note as opposed to \footnote. In processing a tag in the xml, I need to test if the current ref node has an ancestor with attribute: @xml:id='apr_engl'. If it does, I need to create a \footnote whose text comes from a element with attribute xml:id='N020-18', if it does not, I need to create a \note whose reference number corresponds to the one created by \footnote and thus points to the same footnote contents: <...> referenced text <...> <...> referenced text <...> footnote contents To result in: arabic text (1) english text (1) (1) footnote content Currently I'm getting: arabic text ?? english text (1) (1) footnote content Document order problem maybe? probably a too complex solution ... this is an alternative: \startbuffer[test] a a a a b b b b ONE TWO \stopbuffer \startxmlsetups xml:somesetups \xmlsetsetup{#1}{text|div|ref|note}{xml:*} \xmlsetsetup{#1}{div[@type='a']}{xml:div:a} \xmlsetsetup{#1}{div[@type='b']}{xml:div:b} \xmlsetsetup{#1}{div[@type='c']}{xml:div:c} \stopxmlsetups \xmlregistersetup{xml:somesetups} \startluacode function document.preprocess() local notes = { } for e in lxml.collected("main","note") do notes[e.at["xml:id"]] = 0 end for e in lxml.collected("main","ref") do local target = e.at["target"] if target then local id = string.gsub(target,"^#","") local n = notes[id] if n then n = n + 1 e.at.footnote = n notes[id] = n e.at["xml:id"] = id end end end end \stopluacode \startxmlsetups xml:text \ctxlua{document.preprocess()} \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:div:a \par[div a]\par \xmlflush{#1} \par[div a]\par \stopxmlsetups \startxmlsetups xml:div:b \par[div b]\par \xmlflush{#1} \par[div b]\par \stopxmlsetups % \startxmlsetups xml:div:c % \par[div c]\par % \xmlflush{#1} % \par[div c]\par % \stopxmlsetups % % \startxmlsetups xml:note % [note \footnote[\letterhash\xmlatt{#1}{xml:id}]{\xmlflush{#1}}] % \stopxmlsetups % % \startxmlsetups xml:ref % [ref : \note[\xmlatt{#1}{target}] ] % \stopxmlsetups \startxmlsetups xml:div:c \stopxmlsetups \startxmlsetups xml:note \stopxmlsetups \startxmlsetups xml:ref \doifsomething{\xmlatt{#1}{footnote}} { \doifelse{\xmlatt{#1}{footnote}} {1} { [footnote \footnote[\xmlatt{#1}{xml:id}]{\xmlflush{#1}}] } { [note \note[\xmlatt{#1}{xml:id}]{\xmlflush{#1}}] } } \stopxmlsetups \starttext \xmlprocessbuffer{main}{test}{} \stoptext (if it works ... wikify it) - 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 ___
Re: [NTG-context] xml attribute conditional
>> @xml:id==string.sub('#N020-18', 2) -> >> (ll.at and ll.at['xml:id'])==string.sub('#N020-18', 2) ! Missing >> number, treated as zero. > > > lua error with sub .. not sure what you want t o test here > > indeed an error will prevent the multipass file to be saved (feature) > > > Hans Thanks Hans, It's good to know the --result problem is not a bug, but a feature. My problem then arises from my use of \note as opposed to \footnote. In processing a tag in the xml, I need to test if the current ref node has an ancestor with attribute: @xml:id='apr_engl'. If it does, I need to create a \footnote whose text comes from a element with attribute xml:id='N020-18', if it does not, I need to create a \note whose reference number corresponds to the one created by \footnote and thus points to the same footnote contents: <...> referenced text <...> <...> referenced text <...> ... footnote contents To result in: arabic text (1) english text (1) (1) footnote content Currently I'm getting: arabic text ?? english text (1) (1) footnote content Document order problem maybe? thanks, Jon ___ 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 ___
Re: [NTG-context] xml attribute conditional
On 13-12-2011 20:21, Jon Crump wrote: @xml:id==string.sub('#N020-18', 2) -> (ll.at and ll.at['xml:id'])==string.sub('#N020-18', 2) ! Missing number, treated as zero. lua error with sub .. not sure what you want t o test here indeed an error will prevent the multipass file to be saved (feature) Hans - 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 ___
Re: [NTG-context] xml attribute conditional
Hans et alia, Thanks for helping out with the right xpath expression. That was indeed the problem: div elements in the ancestor axis that had no xml:id attribute. Unfortunately, this doesn't solve my root problem. I have a tei/xml marked up text with English and Arabic sections. For each ref tag in the english section I want to place a \footnote. For the corresponding ref in the Arabic section I want to place a \note pointing to the same footnote as the corresponding English ref. The minimal example appended below accomplishes this, but when I try to apply this solution to my full text, this solution fails: I get ?? in place of the references in the arabic, lua stats reports: mkiv lua stats > cross referencing - 56 identified, 56 unknown and I get repeated errors of the following sort: xml > lpath > 1 : ex : @xml:id==string.sub('#N020-18', 2) -> (ll.at and ll.at['xml:id'])==string.sub('#N020-18', 2) ! Missing number, treated as zero. which is where, I presume, the ?? references are coming from minimal example follows (\environment ara-sty not included) Any insights you may have would be gratefully received. Jon (PS I suspect that the multiple errors associated with this problem are what's causing --result renaming to fail) xml input: ين لنأخده للغاية تعيس ين لنأخده شايلون شجوات some english referenced text more english referenced text text for note ONE text for note TWO context environment: \startxmlsetups xml:lbsetups \xmlsetsetup{#1}{*}{-} \xmlsetsetup{#1}{body|text|div|p|lb|ref|note}{xml:*} \xmlsetsetup{#1}{div[@type='enText']}{xml:div:entext} \xmlsetsetup{#1}{div[@type='arText']}{xml:div:artext} \xmlsetsetup{#1}{div[@type='fnotes']}{xml:div:fnotes} \xmlsetsetup{#1}{ref}{xml:ref} \xmlsetsetup{#1}{note}{xml:note} \stopxmlsetups \setupfootnotes[location=text] \xmlregistersetup{xml:lbsetups} \environment ara-sty \def\Size{12pt} \enabletrackers[xml.parse,xml.path] \startxmlsetups xml:body \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:text \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:div:entext \setlatin{\switchtobodyfont[palatino,\Size] \xmlflush{#1}} \stopxmlsetups \startxmlsetups xml:div:artext \setarabic{\switchtobodyfont[Arabic] \xmlflush{#1}} \stopxmlsetups \startxmlsetups xml:div:fnotes \placefootnotes \stopxmlsetups \startxmlsetups xml:ref \xmlflush{#1} \xmldoifelse{#1}{ancestor::div[@type='enText']} {\footnote[\xmlatt{#1}{target}] {\xmlfirst{#1} {root::/body/text/div[@type='fnotes']/note[@xml:id==string.sub('\xmlatt{#1}{target}',2)]} } } {\note[\xmlatt{#1}{target}]{}} \stopxmlsetups \startxmlsetups xml:note \xmlflush{#1}\endgraf \stopxmlsetups the ref tag setup that fails for my larger text looks like this: \startxmlsetups xml:ref \xmlflush{#1} \xmldoifelse{#1}{ancestor::div[@xml:id and contains(@xml:id, 'apr_engl')]} %% this expression works {\footnote[\xmlatt{#1}{target}] {\xmlfirst{#1} {root::/TEI/text/back/div[@xml:id=='notes']/note[@xml:id==string.sub('\xmlatt{#1}{target}', 2)]} } } { {\note[\xmlatt{#1}{target}]}{} %% argument to \note results in ?? instead of corresponding ref. number } \stopxmlsetups ___ 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 ___
Re: [NTG-context] xml attribute conditional
On 13-12-2011 00:48, Jon Crump wrote: All, I have a conditional expression that checks to see if the current node has any ancestor whose xml:id attribute matches a string \xmldoifelse{#1}{ancestor::div[@xml:id='apr_engl']} What I need is a test to see if the current node has any ancestor whose xml:id attribute _contains_ a substring. Something like this: \xmldoifelse{#1}{ancestor::div[ @xml:id contains('_engl')]} trying this: \xmldoifelse{#1}{ancestor::div[ contains(@xml:id, '_engl')]} got me this error: ! LuaTeX error< local expr = xml.expressions...>:3: bad argument #1 to 'contains' (string expected, got nil) any suggestions? is there always an id? if not: @xml:id and contains(@xml:id,'_engl') small test file needed (you can run with \enabletrackers[xml.parse,xml.path] to see how it ends up) Hans - 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 ___
[NTG-context] xml attribute conditional
All, I have a conditional expression that checks to see if the current node has any ancestor whose xml:id attribute matches a string \xmldoifelse{#1}{ancestor::div[@xml:id='apr_engl']} What I need is a test to see if the current node has any ancestor whose xml:id attribute _contains_ a substring. Something like this: \xmldoifelse{#1}{ancestor::div[ @xml:id contains('_engl')]} trying this: \xmldoifelse{#1}{ancestor::div[ contains(@xml:id, '_engl')]} got me this error: ! LuaTeX error:3: bad argument #1 to 'contains' (string expected, got nil) any suggestions? Jon ___ 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 ___