ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] Testing whether an XML attribute exists
@ 2023-10-17 10:43 Michael Guravage
  2023-10-17 11:37 ` [NTG-context] " Taco Hoekwater
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Guravage @ 2023-10-17 10:43 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 1161 bytes --]

Hi,

I am typesetting a very simple address list whose source is written in
XML.  Typesetting choices need to be made dependent on the presence of
various attributes; consider the following <family> element.

<family surname="Boer" prefix="den">

If the prefix attribute exists I'l like the name to appear as, e.g. 'Boer,
den."  The several XML attribute testing functions in the XML manual appear
to discriminate on an attribute's value. I tried  \xmldoifnotatt in an
attempt to say, "TRUE if prefix does not match an empty string",  since I
am not interested in the attribute's value but only whether or not it
exists. The code below doesn't work. If someone who knows why it doesn't
work would enlighten my ignorance I would be most grateful. A brief
explanation and example of \xmldoifatt, \xmldoifnotatt, and \xmldoifelseatt
would be exceedingly helpful.

\startxmlsetups xml:list:family
  {\bf \xmlatt{#1}{surname} \xmldoifnotatt{#1, prefix, ''} {,
\xmlatt{#1}{prefix}}} \crlf
  \xmlflush{#1}
\stopxmlsetups

I have attached three files below: an XML address list, the ConTeXt source
file and the typeset result.

-- 
With kind regards,

Michael Guravage

[-- Attachment #1.2: Type: text/html, Size: 2196 bytes --]

[-- Attachment #2: stooges.xml --]
[-- Type: text/xml, Size: 996 bytes --]

<?xml version="1.0" encoding="utf-8"?>

<addressBook>

  <family surname="Horwitz" prefix="">
    <address street="Bowery" housenumber="42-1" postcode="10003" city="New York"  telephone="(934) 012-3456" />
    <members>
      <member name="Jerome (Curly)" birthday="22.11.1903" email="curly@stooges.com" mobile="(934) 123-4567" />
      <member name="Moses (Moe)" birthday="10.06.1897" email="moe@stooges.com" mobile="(934) 234-5678" />
      <member name="Samuel (Shemp)" birthday="11.03.1895" email="shemp@stooges.com" mobile="(934) 345-6789" />
    </members>
  </family>


  <family surname="Feinberg" prefix="den">
    <address street="Bowery" housenumber="42-2" postcode="10003" city="New York"  telephone="(934) 012-3456" />
    <members>
      <member name="Louis (Lary)" birthday="05.10.1902" email="larry@stooges.com" mobile="(934) 456-7890" />
      <member name="Mabel" maiden_name="Haney" birthday="05.21.1904" email="mabel@stooges.com" />
    </members>
  </family>

</addressBook>

[-- Attachment #3: stooges.tex --]
[-- Type: text/x-tex, Size: 1008 bytes --]

\startxmlsetups xml:list:base
  \xmlsetsetup{#1}{addressBook|family|address|members|member}{xml:list:*}
\stopxmlsetups

\xmlregisterdocumentsetup{list}{xml:list:base}

\startxmlsetups xml:list:addressBook
  \title{Address List}
  \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:list:family
  %% {\bf \xmlatt{#1}{surname} \xmldoifnotatt{#1, prefix, ''} {, \xmlatt{#1}{prefix}}} \crlf
  {\bf \xmlatt{#1}{surname}}\crlf
  \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:list:address
  \xmlatt{#1}{street} \xmlatt{#1}{housenumber}\crlf
  \xmlatt{#1}{postcode}\crlf
  \xmlatt{#1}{city}\crlf
  \xmlatt{#1}{telephone}\crlf
  \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:list:members
  \starttabulate[|l|l|l|l|]
    \xmlflush{#1}
  \stoptabulate
\stopxmlsetups


\startxmlsetups xml:list:member
 \NC \xmlatt{#1}{name} {\tfxx \xmlatt{#1}{maiden_name}} \NC \xmlatt{#1}{birthday} \NC \xmlatt{#1}{email} \NC \xmlatt{#1}{mobile} \NC\NR
\stopxmlsetups

\starttext
  \xmlprocessfile{list}{stooges.xml}{}
\stoptext

[-- Attachment #4: stooges.pdf --]
[-- Type: application/pdf, Size: 13273 bytes --]

[-- Attachment #5: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [NTG-context] Re: Testing whether an XML attribute exists
  2023-10-17 10:43 [NTG-context] Testing whether an XML attribute exists Michael Guravage
@ 2023-10-17 11:37 ` Taco Hoekwater
  2023-10-17 11:43   ` Hans van der Meer via ntg-context
  0 siblings, 1 reply; 3+ messages in thread
From: Taco Hoekwater @ 2023-10-17 11:37 UTC (permalink / raw)
  To: mailing list for ConTeXt users



> On 17 Oct 2023, at 12:43, Michael Guravage <guravage@literatesolutions.com> wrote:
> 
> Hi,
> 
> I am typesetting a very simple address list whose source is written in XML.  Typesetting choices need to be made dependent on the presence of various attributes; consider the following <family> element. 
> 
> <family surname="Boer" prefix="den">
> 
> If the prefix attribute exists I'l like the name to appear as, e.g. 'Boer, den."  The several XML attribute testing functions in the XML manual appear to discriminate on an attribute's value. I tried  \xmldoifnotatt in an attempt to say, "TRUE if prefix does not match an empty string",  since I am not interested in the attribute's value but only whether or not it exists. The code below doesn't work. If someone who knows why it doesn't work would enlighten my ignorance I would be most grateful. A brief explanation and example of \xmldoifatt, \xmldoifnotatt, and \xmldoifelseatt would be exceedingly helpful.
> 
> \startxmlsetups xml:list:family
>   {\bf \xmlatt{#1}{surname} \xmldoifnotatt{#1, prefix, ''} {, \xmlatt{#1}{prefix}}} \crlf


Syntax error there, you need:

  \xmldoifnotatt{#1}{prefix}{}{, \xmlatt{#1}{prefix}}

Best wishes,
Taco
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [NTG-context] Re: Testing whether an XML attribute exists
  2023-10-17 11:37 ` [NTG-context] " Taco Hoekwater
@ 2023-10-17 11:43   ` Hans van der Meer via ntg-context
  0 siblings, 0 replies; 3+ messages in thread
From: Hans van der Meer via ntg-context @ 2023-10-17 11:43 UTC (permalink / raw)
  To: NTG ConTeXt; +Cc: Hans van der Meer


[-- Attachment #1.1: Type: text/plain, Size: 1974 bytes --]

But there is also
	\ifxmlattempty{#1}{prefix} .. \else .. \fi

yours sincerely
dr. Hans van der Meer



> On 17 Oct 2023, at 13:37, Taco Hoekwater <taco@bittext.nl> wrote:
> 
> 
> 
>> On 17 Oct 2023, at 12:43, Michael Guravage <guravage@literatesolutions.com> wrote:
>> 
>> Hi,
>> 
>> I am typesetting a very simple address list whose source is written in XML.  Typesetting choices need to be made dependent on the presence of various attributes; consider the following <family> element. 
>> 
>> <family surname="Boer" prefix="den">
>> 
>> If the prefix attribute exists I'l like the name to appear as, e.g. 'Boer, den."  The several XML attribute testing functions in the XML manual appear to discriminate on an attribute's value. I tried  \xmldoifnotatt in an attempt to say, "TRUE if prefix does not match an empty string",  since I am not interested in the attribute's value but only whether or not it exists. The code below doesn't work. If someone who knows why it doesn't work would enlighten my ignorance I would be most grateful. A brief explanation and example of \xmldoifatt, \xmldoifnotatt, and \xmldoifelseatt would be exceedingly helpful.
>> 
>> \startxmlsetups xml:list:family
>>  {\bf \xmlatt{#1}{surname} \xmldoifnotatt{#1, prefix, ''} {, \xmlatt{#1}{prefix}}} \crlf
> 
> 
> Syntax error there, you need:
> 
>  \xmldoifnotatt{#1}{prefix}{}{, \xmlatt{#1}{prefix}}
> 
> Best wishes,
> Taco
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
> 
> maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> archive  : https://github.com/contextgarden/context
> wiki     : https://wiki.contextgarden.net
> ___________________________________________________________________________________


[-- Attachment #1.2: Type: text/html, Size: 2852 bytes --]

[-- Attachment #2: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-17 11:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-17 10:43 [NTG-context] Testing whether an XML attribute exists Michael Guravage
2023-10-17 11:37 ` [NTG-context] " Taco Hoekwater
2023-10-17 11:43   ` Hans van der Meer via ntg-context

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