How to handle ampersands in XML with XSLT
Hi
A user has copied and pasted some XML into a block and using XSLT to read the data. I am trying to build a custom feed like the example you have http://www.hannonhill.com/kb/RSS-Feed/
When viewing the feed within Cascade, I get the error:
An error occurred: An error occurred during the parsing of the assembled page XML: org.xml.sax.SAXParseException: The reference to entity "ID" must end with the ';' delimiter.
However, the ampersand seems to be causing a problem in the XML
<description>
<url>http://www.mysite.com?page=3&ID=333</url>
</description>
This works when changing it to &, but is is unreasonable to ask the user to swap out all instances of & to & within the XML as it is quite large and will have tonnes of instances of this occurring.
<description>
<url>http://www.mysite.com?page=3&ID=333</url>
</description>
Is there a way around this issue in XSLT to get this to work?
Thanks
Cheers
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ryan Griffith on 15 Apr, 2016 12:35 PM
Hi Ray,
I actually helped a client with a similar situation where the resulting content contained unencoded
&
characters and threw the error message.The solution I came up with was to use a Xalan function that encodes all ampersands that are not encoded.
Please let me know if you have any questions.
Thanks!
2 Posted by Raymond Choo on 15 Apr, 2016 03:38 PM
Hi
Thanks so much, that seems to have worked.
Cheers
3 Posted by Ryan Griffith on 15 Apr, 2016 03:44 PM
Not a problem at all, Ray. I am glad to hear the proposed code did the trick.
I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.
Have a great day!
Ryan Griffith closed this discussion on 15 Apr, 2016 03:44 PM.