Hi, Am converting HTML to XML using java, XSLT. The HTML contains element having attribute value with white spaces, for example <span attr1="There is double space here">some text</span> The attr1 value contains two white spaces. When I convert this to Xml using XSLT, the extra white space is stripped.How can I preserve extra whitespaces for attribute value of an element. Thanks, Kapil
The XML Recommendation is here. Read section 3.3.3 ("Attribute-Value Normalization") and you will see that an XML parser is required to do what you described there. There is nothing you can do about that.
posted 11 years ago
Thanks for the reply Paul. Does that mean there is no way to have two consecutive spaces in the attribute value (other than to implement custom implementation of parser)?
Yes, that's what it means. And I wouldn't recommend anybody to write a non-compliant XML parser just to violate that rule. After all, you could modify your XML design to put text in text elements where it belongs.
posted 11 years ago
Hi Paul, Am converting XML received from a third party application to Html for editing purpose and then converting it back to Xml. The xml is then returned to this thirdparty application. There are some custom attributes which have to be maintained during this transformation and these attribute may contain white spaces. I have no control over the structure of XML. Is there any way to preserve the spaces? I tested this with Xml Spy and it preserves the extra white spaces but not with XALAN. Thanks, Kapil
You can't preserve the spaces if you use a compliant XML parser. Basically it was a bad design decision to put significant spaces like that into an attribute. It's not your fault that the parser does what it is supposed to do. If there's somebody in a position of authority who thinks it is a problem, they should act to get the XML design fixed.
Crusading Chameleon likes the size of this ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database