I want to remove spaces from all attributes in my xmls using xslt. I used strip-space
, but that removes the spaces from nodes.
My input xml is:
If you just want to removes spaces from the values of attributes, you could just create a template to match any attribute, and then use the translate function.
And if you want to filter out some attributes, you can create templates to match, and then ignore them. (XSLT will match the more specific template first)
You can also simplify you code somewhat by making use of the identity transform to cope existing nodes. Here is the full XSLT
When applied to your sample XML, the following is ouptut
The advantage of this approach is that it will work with any XML document.
If you wanted to do this only for specific elements, try this XSLT instead which explicitly matches the attributes you want (and discards all others)
EDIT: If you wanted to remove only leading and trailing spaces, then 'normalize-space' is your friend.
Do note this will remove excess spaces within the attribute though (that is to say double-spaces become single spaces between words).