• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Preserving whitespaces in attribute value during XSLT  RSS feed

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 23713
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
kapil Gupta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
Paul Clapham
Sheriff
Posts: 23713
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
kapil Gupta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Clapham
Sheriff
Posts: 23713
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!