counting characters when dealing with XML
Dear list, I have a question when dealing with XML. Is there any way to write a conditional based on the number of characters in a given field? I mean, the following field: \xmltext{#1}{h1[@class='subtitle']} If subtitle > 60 chars, then fontsize = 10pt. If subtitle > 50 chars, then fontsize = 12pt. If subtitle > 40 chars, then fontsize = 14pt. If subtitle > 30 chars, then fontsize = 16pt. How could I write these conditionals? Many thanks for your help, Pablo -- http://www.ousia.tk
On 1/20/2015 8:50 PM, Pablo Rodriguez wrote:
Dear list,
I have a question when dealing with XML.
Is there any way to write a conditional based on the number of characters in a given field?
I mean, the following field:
\xmltext{#1}{h1[@class='subtitle']}
If subtitle > 60 chars, then fontsize = 10pt. If subtitle > 50 chars, then fontsize = 12pt. If subtitle > 40 chars, then fontsize = 14pt. If subtitle > 30 chars, then fontsize = 16pt.
How could I write these conditionals?
let tex do the work .. counting is not accurate for this anyway \starttexdefinition AutoFontSize #1 \begingroup \setbox\scratchbox\hbox{#1} \normalexpanded { \definedfont[Regular*default at \ifdim\wd\scratchbox>30em 10pt\else \ifdim\wd\scratchbox>25em 12pt\else \ifdim\wd\scratchbox>20em 14pt\else \ifdim\wd\scratchbox>15em 16pt\fi\fi\fi\fi ] } #1 \endgroup \stoptexdefinition \starttext \dostepwiserecurse{30}{80}{2}{\AutoFontSize{\dorecurse{#1}{x}}\par} \stoptext - ----------------------------------------------------------------- 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 -----------------------------------------------------------------
On 01/21/2015 12:36 AM, Hans Hagen wrote:
On 1/20/2015 8:50 PM, Pablo Rodriguez wrote:
Dear list,
I have a question when dealing with XML.
Is there any way to write a conditional based on the number of characters in a given field? [...] let tex do the work .. counting is not accurate for this anyway
Many thanks for your reply, Hans. I don’t need total accuracy with this. Many thanks for your help again, Pablo
\starttexdefinition AutoFontSize #1 \begingroup \setbox\scratchbox\hbox{#1} \normalexpanded { \definedfont[Regular*default at \ifdim\wd\scratchbox>30em 10pt\else \ifdim\wd\scratchbox>25em 12pt\else \ifdim\wd\scratchbox>20em 14pt\else \ifdim\wd\scratchbox>15em 16pt\fi\fi\fi\fi ] } #1 \endgroup \stoptexdefinition
\starttext \dostepwiserecurse{30}{80}{2}{\AutoFontSize{\dorecurse{#1}{x}}\par} \stoptext
participants (2)
-
Hans Hagen
-
Pablo Rodriguez