XSLT <xsl:element> Element

Definition and Usage

The <xsl:element> element is used to create element nodes in the output document.

Syntax

<xsl:element
name="name"
namespace="URI"
use-attribute-sets="namelist">
  <!-- Content:template -->
</xsl:element>

Attribute

Attribute Value Description
name name Required. Specifies the name of the element to be created (you can use an expression to assign the name attribute, which is calculated at runtime, for example: <xsl:element name="{$country}"/>)
namespace URI Optional. Specifies the namespace URI of the element. (You can use an expression to assign the namespace attribute, which is calculated at runtime, for example: <xsl:element name="{$country}" namespace="{$someuri}"/>)
use-attribute-sets namelist Optional. A set of space-separated attributes that includes the attributes to be added to the element.

Instance

Example 1

An element named "singer" is created, which contains the value of each artist element:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <xsl:for-each select="catalog/cd">
    <xsl:element name="singer">
      <xsl:value-of select="artist" />
    </xsl:element>
    <br />
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

查看 XML 文件查看 XSL 文件查看结果