element

An element statement defines an XML element in the output stream. It has a name and a block containing other keywords.

Syntax
<element> ::= "element" <quote> <name> <quote> ( "namespace" <quote> <URI> <quote> )? ( "use-attribuite-sets" <quote> <name list> <quote> )? "{" ( <block template> )* "}"
Options
name the name of the element.
namespace the XML namespace to be defined for this element (optional).
Elements

Zero or more block elements.

Examples

For example the scrap.

stylesheet { version "1.0" match using "/" { element "body" { attribute "name" "topOfPage" element "a" { attribute "name" "topOfPage" } element "div" { attribute "id" "bodyFrame" apply-templates } } } }

would compile to

<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0"> <template match="/"> <element name="body"> <attribute name="name"> <text>topOfPage</text> </attribute> <element name="a"> <attribute name="name"> <text>topOfPage</text> </attribute> </element> <element name="div"> <attribute name="id"> <text>bodyFrame</text> </attribute> <apply-templates/> </element> </element> </template> </stylesheet>

There are two optional parameters that can specify name-spaces and attribute set for the element and its enclosed block. So for example the above might be extended

stylesheet { version “1.0” match using "/" { element "body" namespace "http://www.w3.org/1999/xhtml" { attribute "name" "topOfPage" element "a" namespace "http://www.w3.org/1999/xhtml" { attribute "name" "topOfPage" } element "div" namespace "http://www.w3.org/1999/xhtml" { attribute "id" "bodyFrame" apply-templates } } } }

giving

<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0"> <template match="/"> <element name="body" namespace="http://www.w3.org/1999/xhtml"> <attribute name="name"> <text>topOfPage</text> </attribute> <element name="a" namespace="http://www.w3.org/1999/xhtml"> <attribute name="name"> <text>topOfPage</text> </attribute> </element> <element name="div" namespace="http://www.w3.org/1999/xhtml"> <attribute name="id"> <text>bodyFrame</text> </attribute> <apply-templates /> </element> </element> </template> </stylesheet>
Errors

No opening bracke:

stylesheet { version “1.0” match using "/" { element "div" attribute "id" "bodyFrame" apply-templates } } }

will give the error

**** (106) Unexpected symbol "attribute" in line 6 Check spelling, did you mean start of block bracket? **** (136) Unmatched brackets in 1 Too many close brackets?

Leaving out the namespace expression:

stylesheet { version “1.0” match using "/" { element "div" namespace { attribute "id" "bodyFrame" apply-templates } } }

will give the error

**** (130) Missing expression after "namespace" in line 5 Insert expression.
Copyright 2024 Hugh Field-Richards. All Rights Reserved.