Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Values can be obtained from an attribute in XSLT using the xsl:value-of or xsl:attribute element. Once the value is obtained, it can be stored in a variable using the xsl:variable element.

To change the values of other attributes, the xsl:attribute element is used, along with an expression that evaluates the new attribute value. For example:

<template>
  <xsl:template match="div[@class='old-class']">
    <xsl:variable name="newClass" select="'new-class'" />
    <div>
      <xsl:attribute name="class">
        <xsl:value-of select="$newClass" />
      </xsl:attribute>
      <xsl:apply-templates />
    </div>
  </xsl:template>
</template>

In this example, the XSLT template matches a div element with a class of old-class. The value of new-class is stored in a variable named newClass. The xsl:attribute element is then used to set the value of the class attribute to the value of the newClass variable. Finally, the xsl:apply-templates element is used to process any child nodes of the div element.