Example 2 of <xsl:attribute>

This example demonstrates how to use attribute value templates to use content in the XML source document as the name of an attribute.

XML File (attribute.xml)

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="attribute.xsl"?>
   <price type="high">100</price>
   <price type="low">94</price>

XSLT File (attribute.xsl)

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" indent="yes"/>

<xsl:template match="investment">
   <xsl:element name="{type}">
      <xsl:attribute name="name" >
         <xsl:value-of select="name"/>
      <xsl:for-each select="price">
      <xsl:attribute name="{@type}" >
         <xsl:value-of select="."/>


There is no formatted output. This is the processor output:

<?xml version="1.0"?>

<stock name="Microsoft" high="100" low="94">