XMLIF(1)

πŸ“¦
version 0.0.29 Β· 2 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’… XMLIF(1) β€” like, the xmlif page, bestie ✨

okay so welcome to the xmlif manual, section 1 of the manual, and honestly? this one's a lil gem. it's in the xmlif corner of the man pages and we're about to make it make sense 🫢


🌸 NAME 🌸

xmlif β€” conditional processing instructions for XML. yes bestie, it's giving "if statements but make it XML" πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

xmlif [attrib=value...]

like. that's it. that's the whole vibe. you pass it attrib=value pairs and it does the thing ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea β˜• β€” xmlif filters XML according to conditionalizing markup. lowkey iconic behaviour. it's useful when you wanna format one of several versions of an XML document depending on conditions you pass to the command. one source file, many outputs, main character energy fr fr πŸ‘‘

the attribute/value pairs you give on the command line get matched against the attributes associated with certain processing instructions in the document. and the instructions in question? let me list them for you, no skips, no cap:

  • <?xmlif if?> and its inverse <?xmlif if not?>
  • <?xmlif elif?> and its inverse <?xmlif elif not?>
  • <?xmlif else?>
  • <?xmlif fi?>

not me listing every single one because i respect the source material πŸ’€πŸ’…


🧚 the matching rules (this is the important part, stay with me)

argument/value pairs given on the command line get checked against the value of corresponding attributes in the conditional processing instructions. so:

  • an attribute match happens if an attribute occurs in both the command-line arguments and the tag, and the values match βœ…
  • an attribute mismatch happens if an attribute occurs in both the command-line arguments and the tag, but the values do not match ❌

periodt. that's the whole matching mechanic πŸ“


🌈 what actually gets passed through

spans between <?xmlif if?> or <?xmlif elif?> and the next conditional processing instruction at the same nesting level are passed through unaltered if there is at least one attribute match and no attribute mismatch. slay.

spans between <?xmlif if not?> and <?xmlif elif not?> and the next conditional processing instruction are passed otherwise. (yes, inverse behaviour, we love a flip πŸ”„)

spans between <?xmlif else?> and the next conditional-processing tag are passed through only if no previous span at the same level has been passed through. it's the fallback bestie, it only shows up when nobody else did πŸ™ˆ

nesting levels, real quick:

  • <?xmlif if?> and <?xmlif fi?> (and their not variants) change the current nesting level πŸ“ˆ
  • <?xmlif else?> and <?xmlif elif?> do not change it 🚫

✨ and then what happens to the tags

all these processing instructions will be removed from the output produced. gone. deleted. not in the final cut πŸ’…

aside from the conditionalization, all other input is passed through untouched. and in particular β€” and this is highkey important β€” entity references are not resolved. not resolved. leave them alone. that's the rule πŸ”₯


⭐ value matching (the | thing, iykyk)

value matching is by string equality, except that "|" in an attribute value is interpreted as an alternation character. so like:

  • saying foo='red|blue' on the command line enables conditions red and blue 🌈
  • saying color='black|white' in a tag matches command-line conditions color='black' and color='white' πŸ–€πŸ€

it's giving "or" but make it a pipe character. obsessed.


🫢 the example, verbatim, because it eats

Always issue this text.
<?xmlif if condition='html'?>
Issue this text if 'condition=html' is given on the command line.
<?xmlif elif condition='pdf|ps'?>
Issue this text if 'condition=pdf' or 'condition=ps'
is given on the command line.
<?xmlif else?>
Otherwise issue this text.
<?xmlif fi?>
Always issue this text.

see how the always-text is always there? iconic. the conditional stuff in between does the picking. the fi closes it out like a good little closer πŸŽ€


πŸ’œ AUTHOR πŸ’œ

Eric S. Raymond <esr@snark.thyrsus.com>

  • Author of xmlif program

the legend himself, we stan πŸ‘‘


🌟 SEE ALSO 🌟

(nothing listed in this one bestie, this page is a solo act πŸ’…)


and that's the whole page!! this XMLIF(1) beauty comes to us from the xmlif manual, sourced from Linux, dated April 2009 β€” and honestly it aged like fine wine fr fr. mwah, bye bestie πŸ’–πŸ¦‹βœ¨