attribute-set
An attribute-set creates a named set of attributes, which can be used
within other elements my referencing the name.
Syntax
<attribute-set> ::= “attribute-set” <quote> <qname> <quote>
( “use-attribute-sets” <name list> )?
“{”
<attribute>+
“}”
Options
name
|
a QName defining the name of this atttribute set. |
use-attribute-sets
|
an (optional) string containing a whitelist separated list of other sets. |
Elements
One or more attribute definitions.
Examples
match using "//list" {
apply-templates {
with param-1 "'List Title'"
sort using "a" descending
}
}
A trivial example for having common attributes which might occur throughout an HTML file.
stylesheet {
version "1.1"
attribute-set "block-style" {
attribute "font-size" "12pt"
attribute "font-weight" "bold"
}
attribute-set "block-margin" {
attribute "leading" "12pt"
attribute "margin-top" "24pt"
}
match using "/" {
element "block" use-attribute-sets "block-style block-margin" {
attribute "id" "start"
text "Some block text"
}
}
}
To show how the above works, consider a one line XML file:
<?xml version="1.0" encoding="UTF-8"?>
<test-attribute/>
Running the XSLT we get
<?xml version="1.0" encoding="UTF-8"?>
<block
font-size="12pt" font-weight="bold"
leading="12pt" margin-top="24pt"
id="start">Some block text</block>
Errors
Forgetting the leading block bracket.
attribute-set "block-style"
attribute "font-size" "12pt"
attribute "font-weight" "bold"
}
will give the error
**** (104) Missing "{" in line 5
Insert bracket.
Forgetting the name of the attribute set
stylesheet {
version "1.1"
attribute-set {
attribute "font-size" "12pt"
attribute "font-weight" "bold"
}
attribute-set "block-margin" {
attribute "leading" "12pt"
attribute "margin-top" "24pt"
}
match using "/" {
element "block" use-attribute-sets "block-style block-margin" {
attribute "id" "start"
text "Some block text"
}
}
}
will give two errors.
**** (115) Expected name after "attribute-set" in line 4
Insert name.
**** (116) Could not find "block-style" in line 15
Check "block-style" is defined in current block/context.
Copyright 2024 Hugh Field-Richards. All Rights Reserved.