Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Preserving whitespaces in attribute value during XSLT

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 27211
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 27211
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 27211
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic