An XSLT style sheet can instruct an XSLT processing program to add new elements and attributes to the output.
xsl:element
The xsl:element element creates a named element. The syntax is as follows:
<xsl:element name="element-name">
The following sample XSL code snippet creates an HTML form <input> tag field (for data entry). This code snippet will ultimately be part of a web page using XML and XSL formatting, where the XSL code includes HTML tags, which you will see shortly:
<xsl:element name="input">
...
</xsl:element>
the html equivalent of the preceding sample script snippet is something like this:
<html><body>
...
<input ... >
...
</body></html>
xsl:attribute
The xsl:attribute element adds attributes to elements. The syntax is as follows:
<xsl:attribute name="attribute-name">
This sample code snippet adds attributes to the HTML <INPUT> tag. Again, this code snippet will ultimately become part of a web page using XML and XSL formatting, where the XSL code includes HTML tags:
<xsl:element name="input">
<xsl:attribute name="value"></xsl:attribute>
<xsl:attribute name="size">40</xsl:attribute>
</xsl:element>
Once again, the HTML equivalent of the preceding sample script snippet is something like this:
<html><body>
...
<input value="" size="40"/>
...
</body></html>
You can also use xsl:attribute-set element to create an attribute set that can be applied to any output element:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html"/>
<xsl:attribute-set name="input-attrs">
<xsl:attribute name="value"></xsl:attribute>
<xsl:attribute name="size">40</xsl:attribute>
</xsl:attribute-set>
...
<xsl:element name="input" use-attribute-sets="input-attrs">
...
</xsl:element>