The <xsl:attribute> element allows you to dynamically or conditionally add attributes.

  name = { qname }
  namespace = { uri-reference }>
  <!-- Content: template -->

The attribute name


The namespace URI reference for the attribute

An example of <xsl:attribute> being used conditionally:

<xsl:template name="graphic">
  <img src="{@fileref}">
    <xsl:if test="@align">
      <xsl:attribute name="align">
        <xsl:value-of select="@align"/>

Note that the <img> tag has logical content in the stylesheet. The serializer is expected to render this appropriately for HTML or XML.