How to handle ampersands in XML with XSLT

Ray's Avatar

Ray

14 Apr, 2016 09:23 PM

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 &amp;, but is is unreasonable to ask the user to swap out all instances of & to &amp; 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&amp;ID=333</url>
</description>

Is there a way around this issue in XSLT to get this to work?
Thanks
Cheers

  1. 1 Posted by Ryan Griffith on 15 Apr, 2016 12:35 PM

    Ryan Griffith's Avatar

    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. 2 Posted by Raymond Choo on 15 Apr, 2016 03:38 PM

    Raymond Choo's Avatar

    Hi
    Thanks so much, that seems to have worked.

    Cheers

  3. 3 Posted by Ryan Griffith on 15 Apr, 2016 03:44 PM

    Ryan Griffith's Avatar

    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!

  4. Ryan Griffith closed this discussion on 15 Apr, 2016 03:44 PM.

Comments are currently closed for this discussion. You can start a new one.

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