Pages

Wednesday, September 12, 2012

Use xsl:value-of to retrieve attribute values for output

A valuable method for retrieving attribute values to output their contents is with the xsl:value-of element. For example, your XML document has an element called biblioref, which has a sequence attribute:

<para>This is a bibliography reference.<biblioref sequence="1">.</para>

You want to output that attribute as a superscripted number in HTML on your web page:

      This is a bibliography reference.1

Use xsl:value of in your XSLT stylesheet to retrieve and output the attribute, like so:

<xsl:template match="biblioref">
      <sup>
      <xsl:value-of select="@sequence"/>
      </sup>
</xsl:template>

This XSLT rule says to match the biblioref tag, output the open <sup> tag, output the value of the sequence attribute, and then output the close </sup> tag.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.