preserve-space/strip-space
preserve-space and strip-space statements define the elements in the source
document whose whitespace should be preserved or removed respectively. They are defined by a list of whitespace separated names. This list
can also contain "*" and "namespacePrefix:*" so that all elements from either the default namespace or a particular namespace can be
included.
Because the default in a stylesheet is to preserve space thepreserve-space is necessary when strip-space is used.
Syntax
<preserve-space> ::= “preserve-space” <quote> <name list> <quote>
<strip-space> ::= “strip-space” <quote> <name list> <quote>
Options
name list
|
A whitespace list of element names in which to preserve/strip the space. |
Elements
None.
Examples
It is possible to be selective and only include certain elements. For example
stylesheet {
version "1.0"
xmlns "a" "http://relaxng.org/ns/annotation/1.0"
xmlns "xhtml" "http://www.w3.org/1999/xhtml"
preserve-space "a:* pre"
strip-space "code"
}
Preserves whitespace in all elements within the 'http://relaxng.org/ns/annotation/1.0' namespace, and also
all spaces within <pre> elements. It strips the white-space from all <code> elements.
It would compile to
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet
version="1.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:a="http://relaxng.org/ns/annotation/1.0"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<preserve-space elements="a:* pre"/>
<strip-space elements="code"/>
</stylesheet>
Errors
Omitting the element list
stylesheet {
version "1.0"
xmlns "a" "http://relaxng.org/ns/annotation/1.0"
xmlns "xhtml" "http://www.w3.org/1999/xhtml"
preserve-space
parameter param_1
}
will give the error
**** (130) Missing expression after "preserve-space" in line 9
Insert expression.
Note that having a empty string
stylesheet {
version "1.0"
xmlns "a" "http://relaxng.org/ns/annotation/1.0"
xmlns "xhtml" "http://www.w3.org/1999/xhtml"
preserve-space ""
parameter param_1
}
while not strictly correct will not give an error and the statement will be ignored
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet
version="1.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:a="http://relaxng.org/ns/annotation/1.0"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<param name="param_1"/>
</stylesheet>
Copyright 2024 Hugh Field-Richards. All Rights Reserved.