Macro Language Reference > PIs > Formatting Instructions > showifdef
  
showifdef
Description
This command has been implemented primarily with SGML/XML type attributes in mind. <?showifdef> permits the conditional processing of a show string, the condition being the presence of a defined attribute on the SGML/XML element. When the specified condition has been met the command will show the value of the attribute.
 
Example 383. Only show specified text if it is defined in a certain attribute
Let us assume that a requirement was to display the words 'Authors:Dave' in the text stream only if the name attribute was defined. The following text appears in the text stream:
...<author name="Dave" >...
Inside the author tag you would need the following:
<?showifdef "name"Authors:$^name#^>
 
Example 384. Reset an xcounter and set a PI if a specified attribute is defined
If the "id" attribute is defined in the para element, reset the value of the xcounter x(99) to 0 and set the typeface to Times:
<?showifdef "id"[?show=x(99)][?tf="Times"]>
This command would be included in the para style tag to give the required element context for the "id" attribute.
 
Example 385. Set the table gutter if the gutter attribute is defined in the <colspec> tag
If the 'gutter' attribute is defined in the <colspec> tag, ie. <colspec gutter="...">, show the table gutter command <?tbcolgut=?> and use the value of that attribute:
<?showifdef "gutter"$60#?tbcolgut==$^gutter#^$62#>
 
The use of variables in the resulting code means the chevrons must be replaced with their ASCII value ($60# and $62#, and = (equals) characters to be doubled up.
 
Example 386. Yank text if attribute defined
If the 'name' attribute is defined in the <authors> tag, insert a showstring that will yank the text up to the </authors> end tag and insert the resulting yanked text , preceded with the style tag <name_style>, into a reference tag called 'Authmn'.
In text stream Tx1:
...<authors name="Chris">This manual was......</authors>
In style tag authors:
<?showifdef "name"$60#?show "Authmn"\[name_style\]\$1,0,
63y"/\\60\\\\47\\authors\\62\\/ci"$62#>
 
Note the $60# and the double \\ in the search string. Note also the \[ & \] around the style tag, instructing PTC ALD not to process yet.
Syntax
<?showifdef !:L? ( inheritance:L? name:s )> mode:L? test:sw? action:sw>
!
Use the opposite condition: instead of show if defined , use show if NOT defined.
inheritance
This parameter was implemented to control attribute inheritance when using XML in PTC ALD and the <?showifdef> command: it replaces the need to use XPath expressions.
* 
The selected option is inserted within the double quotes of the attribute name parameter but must also be surrounded by a further set of single quotes since the curly bracket is a special character, e.g.<?showifdef "'}id'"Show this>:
}
No default attribute inheritance from parent, get the attribute from the current element (or self) only
{
Inherit attribute values from parent
name
Specify that the name of the attribute for which to test must be present. i.e.:
If <?showifdef "fred"Hello> is set inside the <body> style tag, it will display "Hello" for <body fred> or <body fred=1> but not for <body>.
mode
Ø
String comparison of the value of name against action: action will be shown will be displayed if they match.
@
As above, with added case sensitivity
*
A wild card comparison. i.e. <?showifdef "fred*=c*"Hello> will display Hello only if fred begins with c or C.
@*
A case sensitive wild card comparison
/
Test the value of name with a regular expression. action will be displayed if a match for the regular expression is contained within the value of name. To test for an exact match, use ^ and $ at the start and end of the regular expression. (see Technote 0011: Regular Expressions for permitted operators).
@/
A case sensitive regular expression match.
#
Tests the value of name with a verify string, i.e.: <?showifdef "fred#=1..5i> will test for a integer in the range 1 to 5. <?showifdef "fred#=c> tests for a colour. <?showifdef "fred#=u> tests for a unit: e.g. 5mm, 7pt.
test
If name is present its value must be preceded by an equals sign, i.e. <body fred=1>. This parameter will produce different results depending on which mode parameter has been set.
* 
In its simplest form, without any test the show string will be used if the attribute is present even if not given an explicit value.
action
Any applicable showstring or display text.
For more information, see Technote 0011: Regular Expressions and Reference Chapter: Showstrings.