Attributes

Attributes may play an important role in selecting elements by context. Attributes may also contain values that need to be presented, or used to determine what is presented. In some cases it is necessary to know whether an attribute is required to be present, or is optional, or to determine what possible values the attribute may hold. The ATTRIBUTE declaration defines one or more attributes for a given element. The element name follows the declaration keyword. In the example below, the Para element has four attributes assigned to it, namely an 'ID' attribute, a 'Type' attribute, an 'Author' attribute and a 'Status' attribute:

<!ATTLIST Para  ID     #REQUIRED
                Type   (Normal|Secret) "Normal"
                Author #IMPLIED
                Status "draft">

If the attribute name is followed by the keyword #REQUIRED, then the element will always have this attribute present and it will always have a value. It is therefore not necessary to test for its presence in a template. However, if the attribute name is followed by the keyword #IMPLIED, then the attribute may be absent and it is appropriate to test for its existence.

<template name="Para[@Author]">...</template>


<template name="Para">
  <if test="@Author">...</if>
</template>

When a list of values is given between brackets, separated by vertical bar characters, this is the allowed list of values. The values 'Normal' and 'Secret' for the Type attribute above are typical. Again, these are case-sensitive.

Sometimes, a following default value is given, as in 'Normal' and 'draft' above, indicating that when a value is not present in the element tag, this value should be assumed. Depending on the parser used by the XSLT processor, the default may or may not be passed to the processor as an attribute value that is present. It is safer to test for its existence.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset