• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

convert & to &

 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This could be one of the most common questions you can think of when dealing with xsl, but still I am unable to get past. Here's the scenario...

I have an xml attribute caption with value attribute that will be used as a value of "value" attribute of the JSF's command button. So, this caption element may contain something like "&" for &.
Ideally, on my JSP the button should be displayed as "Save & Exit", but it doesn't, rather it is displayed as "Save & Exit"

So the caption attribute's value in the xml is "Save & Exit".

Now, what I want is while xsl transformation is going on, this attribute value be changed to "Save & Exit" and corresponding JSF command button be generated as...



But, somehow, it still generates



I tried to use this template-



And the above template gets called from here




Any idea what's wrong here ? I am using XSL version 1.0, BTW. I can't also use escape attribute of JSF command button since the version we are working on doesn't support escape attribute.

Thanks.


 
Marshal
Posts: 28193
95
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

Girish Vasmatkar wrote:I have an xml attribute caption with value attribute that will be used as a value of "value" attribute of the JSF's command button. So, this caption element may contain something like "&" for &.
Ideally, on my JSP the button should be displayed as "Save & Exit", but it doesn't, rather it is displayed as "Save & Exit"

So the caption attribute's value in the xml is "Save & Exit".



If you look at the title of your post, and read what you posted, it appears to be nonsense. (Read it yourself and see if you agree.) But it's really because you don't understand the escaping of ampersands in HTML and XML. And that escaping is at the root of your problem. So first you should learn how it actually works. If you want an ampersand to appear then you must use "&", which is the escaped form. And if you want "&" to appear in an escaped form -- as I did when I typed the first part of this sentence -- then you must use "&". Try that out for yourself by posting a response which appears the way you want it to appear.

And therefore your problem is unlikely to be solved by doing that replacement which you are trying to do. It's more likely to be solved by escaping things properly in the right place.

Unfortunately I don't have any suggestions because I can't tell what you are trying to do. (That's because you asked for help on your failed non-solution rather than on the original problem.) It looks to me like you're trying to generate JSF code via XSLT, but surely that can't be the case?
 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If you look at the title of your post, and read what you posted, it appears to be nonsense. (Read it yourself and see if you agree.) But it's really because you don't understand the escaping of ampersands in HTML and XML. And that escaping is at the root of your problem. So first you should learn how it actually works. If you want an ampersand to appear then you must use "&", which is the escaped form.



Yeah, I did that for most of the part of post (&) and I did for title too, but you know, now my thread's title appears wrong now on the list of the threads. Anyway, I am trying to generate the JSF page using XSLT.


And therefore your problem is unlikely to be solved by doing that replacement which you are trying to do. It's more likely to be solved by escaping things properly in the right place.



I don't think so, mere escaping can't be the solution here. I think the only way I can get the button to show "Save & Exit" on itself is to have this code in place-



which is only possible if the XSL code itself replaces the attribute value. Are you talking about

?

Which I don't think is the right choice here.

Thank you for the reply.
 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I may be wrong, but may be clarifying things will help-

 
Paul Clapham
Marshal
Posts: 28193
95
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're really trying to generate JSF from XSLT? Wow.

But anyway the example you displayed:

isn't valid XML because the ampersand isn't escaped. It should look like this:


Which means that the disable-output-escaping attribute isn't what you want.
 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sadly enough, this is what our current implementation does and we've got to stick with it.

By the way, the



Would be the code in the JSP and right now the JSP that's generated looks something like this-



If this were the case with <h:outputText/>, I'd have simply used escape="false", but commandButton doesn't have such attribute.
 
Paul Clapham
Marshal
Posts: 28193
95
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
I see. So in effect the only HTML which works for you is invalid HTML (because the ampersand isn't escaped correctly)? And the invalid HTML actually results in different output than the valid HTML?
 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, when this JSF code gets converted in the HTML (view source), I see these things-

JSF code -




HTML generated code -


JSF code -




HTML generated code -




 
Paul Clapham
Marshal
Posts: 28193
95
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
I see. So I shouldn't really consider JSF as a dialect of HTML. It doesn't seem to have the same escaping rules as HTML and XML. Have you tried <xsl:output method="text">? If that doesn't work then this may be a place where disable-output-escaping is required.
reply
    Bookmark Topic Watch Topic
  • New Topic