ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	Michael Guravage <guravage@literatesolutions.com>
Subject: [NTG-context] Re: XML processing, unwanted indentation/alignment
Date: Thu, 15 Feb 2024 22:03:45 +0100	[thread overview]
Message-ID: <d980a07a-b978-ee7c-6f9d-0e51d4e50d5b@gmail.com> (raw)
In-Reply-To: <CAL-A5LYre0jNp+=2e3FFST__2g1rU19YtTuGLAchiX0u=o7VHg@mail.gmail.com>

Michael Guravage schrieb am 15.02.2024 um 21:28:
> Greetings,
> 
> I'm typesetting an address book whose addresses are in XML. A typical 
> entry has this structure:
> 
>    <family surname="">
>      <address street="" housenumber="" postcode="1" city=""  telephone="" />
>      <members>
>        <member first_name="" initials="" maiden_name="" birthday="" 
> email="" mobile="" />
>        <member first_name="" initials="" birthday="" email="" mobile="" />
>        <member first_name="" initials="" birthday="" />
>      </members>
>    </family>
> 
> initials and birthday are required, first_name can be left blank and 
> email, mobile and maiden_name are optional.
> 
> I've written a macro (name) to compose the name, i.e. initials, 
> first_name (maiden_name), and another macro (nameemaillink) to make the 
> name a link associated with an email address.
> 
> % Derive an individual's name
> \def\name#1%
>    {\ifxmlattempty{#1}{first_name} {\xmlatt{#1}{initials}} \else 
> {\xmlatt{#1}{initials}, \xmlatt{#1}{first_name}} \fi
>     \ifxmlattempty{#1}{maiden_name} {} \else { 
> \tfxx(\xmlatt{#1}{maiden_name})} \fi}

You have a few spaces in the definition of your command (e.g. the space 
after \else and another one after the following { in the main_name 
attribute) which end as multiple spaces in the output.

While you can fix the problem by removing the spaces a better solution 
is to use the texdefinition environment to create your command, you can 
even use blank lines to structure the arguments.

To avoid problems with existing commands it is good practice to use 
camelcase for your own commands.

%%%% begin example
\starttexdefinition Name #1

   \ifxmlattempty{#1}{first_name}
     \xmlatt{#1}{initials}
   \else
     \xmlatt{#1}{initials}, \xmlatt{#1}{first_name}
   \fi

   \ifxmlattempty{#1}{maiden_name}
     %
   \else
     {\tfxx(\xmlatt{#1}{maiden_name})}
   \fi

\stoptexdefinition
%%%% end example

Wolfgang
___________________________________________________________________________________
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
___________________________________________________________________________________

  reply	other threads:[~2024-02-15 21:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-15 20:28 [NTG-context] " Michael Guravage
2024-02-15 21:03 ` Wolfgang Schuster [this message]
2024-02-15 23:34 ` [NTG-context] " Bruce Horrocks
2024-02-16  8:32   ` Taco Hoekwater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d980a07a-b978-ee7c-6f9d-0e51d4e50d5b@gmail.com \
    --to=wolfgang.schuster.lists@gmail.com \
    --cc=guravage@literatesolutions.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).