Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XSLT <xsl:element> elements


May 28, 2021 XSL T


Table of contents


XSLT and lt;xsl: element.gt; element

The XSLT-lt;xsl:element-gt; element is used to create an element into the output document.


XSLT <xsl:element> elements Complete XSLT element reference manual

Definitions and usages

The element is used to create element nodes in the output document.


Grammar

<xsl:element
name="name"
namespace="URI"
use-attribute-sets="namelist">

<!-- Content:template -->

</xsl:element>

Property

Attributes value describe
name name 必需。规定要创建的元素的名称。(可以使用表达式为 name 属性赋值,这个表达式是在运行时进行计算的,比如:<xsl:element name="{$country}" />)
namespace URI 可选。规定元素的命名空间 URI。(可以使用表达式为 namespace 属性赋值,这个表达式是在运行时进行计算的,比如:<xsl:element name="{$country}" namespace="{$someuri}"/>)
use-attribute-sets namelist Optional.Space separated attribute set list, which contains properties that need to be added to elements.

Instance 1

Create an element named "singer" that 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>

XSLT <xsl:element> elements Complete XSLT element reference manual