In XSLT, The normalize-space function is used to clear leading and trailing spaces of elements.
Zuo zhiquan
According to my understanding, XSLT is responsible for displaying data stored in XML files. The Style and style displayed by the results of the same XML file combined with different XSLT can be quite different.
It may also be because of its powerful functions. XSLT has many syntaxes and functions, but it seems that there are very few materials to introduce and it is often labor-intensive to apply it.
Now there is a question: how do I remove spaces before and after the data obtained from XML before analysis in XSLT? For example:
<XSL: Choose>
<XSL: When test = ". [A =''] ">
<P> element a is empty </P>
</XSL: When>
<XSL: When test = ". [B =''] ">
<P> element B is empty </P>
</XSL: When>
<XSL: otherwise>
<P> Elements A and B are not empty </P>
</XSL: otherwise>
</XSL: Choose>
As a result, data that appears to be empty on the surface of a and B, such as <A> </a> <B> </B>, all output elements A and B are not empty. Obviously, no leading and trailing spaces in the elements are deleted during comparison.
How can I delete these spaces? In C # or other languages, trim flew over to fix it.
I searched the internet and found that I could use the normalize-space function.
However, I failed to try it, saying that normalize-space is not supported. Later, I looked at the XSLT file header and almost vomited blood. I used the old version of namespace:
<XSL: stylesheet xmlns: XSL = "http://www.w3.org/TR/WD-xsl">
Change to the namespace of the new version:
<XSL: stylesheet version = "1.0" xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">
The problem is solved.
<XSL: Choose>
<XSL: When test = "normalize-space (A) ='' ">
<P> element a is empty </P>
</XSL: When>
<XSL: When test = "normalize-space (B) ='' ">
<P> element B is empty </P>
</XSL: When>
<XSL: otherwise>
<P> Elements A and B are not empty </P>
</XSL: otherwise>
</XSL: Choose>