ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* counting characters when dealing with XML
@ 2015-01-20 19:50 Pablo Rodriguez
  2015-01-20 23:36 ` Hans Hagen
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Rodriguez @ 2015-01-20 19:50 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________
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] 3+ messages in thread

* Re: counting characters when dealing with XML
  2015-01-20 19:50 counting characters when dealing with XML Pablo Rodriguez
@ 2015-01-20 23:36 ` Hans Hagen
  2015-01-22 18:32   ` Pablo Rodriguez
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Hagen @ 2015-01-20 23:36 UTC (permalink / raw)
  To: ntg-context

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
-----------------------------------------------------------------
___________________________________________________________________________________
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] 3+ messages in thread

* Re: counting characters when dealing with XML
  2015-01-20 23:36 ` Hans Hagen
@ 2015-01-22 18:32   ` Pablo Rodriguez
  0 siblings, 0 replies; 3+ messages in thread
From: Pablo Rodriguez @ 2015-01-22 18:32 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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

-- 
http://www.ousia.tk
___________________________________________________________________________________
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] 3+ messages in thread

end of thread, other threads:[~2015-01-22 18:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-20 19:50 counting characters when dealing with XML Pablo Rodriguez
2015-01-20 23:36 ` Hans Hagen
2015-01-22 18:32   ` Pablo Rodriguez

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