Ask Your Question
2

How can values be obtained from an attribute in XSLT and used to change the values of other attributes?

asked 2023-06-21 01:05:13 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-06-21 01:14:02 +0000

devzero gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-21 01:05:13 +0000

Seen: 11 times

Last updated: Jun 21 '23