Preserving HTML in XSLT Tranformation

aehsan's Avatar

aehsan

08 Oct, 2014 06:33 PM

Hi,

I have a huge XML feed of Faculty Publications. Some of the fields contain HTML markups that I would like to preserve. I have specified the following at the top:

<xsl:output doctype-public="string" doctype-system="string" encoding="string" indent="yes" media-type="string" method="html" omit-xml-declaration="yes" standalone="yes" version="string"/>

Then to preserve HTML, I am using:

<strong><xsl:copy-of select="TITLE/node()"/></strong>

But all it is doing is outputting the HTML tags and the text.

Anyway to transform so that, for example, if the XML code contains <strong>some text</strong>, I want to to show up as bold text after the transformation.

Any insight would be greatly appreciated.

Thanks,

Akbar

  1. 1 Posted by Ryan Griffith on 08 Oct, 2014 08:37 PM

    Ryan Griffith's Avatar

    Hi Akbar,

    Curious, but have you tried using the following to output the node values?

    <xsl:value-of select="TITLE" disable-output-escaping="yes" />
    

    The disable-output-escaping attribute tells XSLT to output the special characters as-is, rather than escaping them.

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by aehsan on 09 Oct, 2014 12:56 PM

    aehsan's Avatar

    Hi Ryan,

    Thanks. That does the job for preserving properly coded HTML tags. Is there way to somehow bringinh in HTML entities like &pound; or &copy; without the script erroring out?

    Thanks,

    Akbar

  3. 3 Posted by Ryan Griffith on 09 Oct, 2014 01:31 PM

    Ryan Griffith's Avatar

    Thank you for following up, Akbar. I am glad to hear the adjustment helped out.

    Regarding the entities, you may be able to declare the entities at the top of the stylesheet so XSLT knows how to handle them properly. Note: You would need to create a separate ENTITY declaration for each one you encounter.

    Please let me know if you have any questions.

    Thanks!

  4. 4 Posted by aehsan on 09 Oct, 2014 01:39 PM

    aehsan's Avatar

    Hi Ryan,

    I keep getting an error trying to code it. My declaration looks like this:

    @@@
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="dmd dmu" version="1.0" xmlns:dmd="http://www.digitalmeasures.com/schema/data-metadata" xmlns:dmu="http://www.digitalmeasures.com/schema/user-metadata">
        <xsl:output doctype-public="string" doctype-system="string" encoding="string" indent="yes" media-type="string" method="html" omit-xml-declaration="yes" standalone="yes" version="string"/>
    @@@

    Are you suggesting it will be separate declaration with a DOCTYPE or will it be part of the same declaration?

    Thanks,

    Akbar

  5. 5 Posted by Ryan Griffith on 09 Oct, 2014 06:42 PM

    Ryan Griffith's Avatar

    Hi Akbar,

    My apologies for the confusion there, I think you may have been looking at the incorrect post from my link.

    What you would do is add the following to the very top of your XSLT Format (above <xsl:stylesheet>:

    <!DOCTYPE xsl:stylesheet [ 
      <!ENTITY nbsp "&#160;">
      <!ENTITY copy "&#169;">
      <!ENTITY copy "&#163;">
    ]>
    

    Please let me know if you have any questions.

    Thanks!

  6. 6 Posted by aehsan on 09 Oct, 2014 06:59 PM

    aehsan's Avatar

    Hi Ryan,

    I copied the Code you gave me as it:

    @@@
    <!DOCTYPE xsl:stylesheet [
        <!ENTITY nbsp "&#160;">
        <!ENTITY copy "&#169;">
        <!ENTITY cent "&#162;">
    ]>
    @@@

    I got the following error on the page that references this format:

    An error occurred: An error occurred during the parsing of the assembled page XML: org.xml.sax.SAXParseException: The entity "copy" was referenced, but not declared.
    You may choose to retry the operation. If the problem persists, please contact a system administrator.
    The error has been logged to the system console.

    Any ideas?

    Thanks,

    Akbar

  7. 7 Posted by Ryan Griffith on 10 Oct, 2014 01:00 PM

    Ryan Griffith's Avatar

    Hm, my apologies that did not work out for you, Akbar.

    I would like to try some things out in my local instance. When you have a moment, please attach your XST Format and either attach the sample XML, or provide a URL to the XML file if you are using a Feed Block to pull it in.

    Please let me know if you have any questions.

    Thanks!

  8. 8 Posted by aehsan on 10 Oct, 2014 03:25 PM

    aehsan's Avatar

    Hi Ryan,

    I am not sure if you can get to the feed URL, but do try this URL:

    https://www.purdue.edu/science/secure/digital_measures_feed/bio_profile.php?user=dkihara

    I am attaching the script and XML after adding &cent; to this professor's one publication.

    Please let us know.

    Thanks,

    Akbar

  9. 9 Posted by Ryan Griffith on 10 Oct, 2014 07:20 PM

    Ryan Griffith's Avatar

    Hi Akbar,

    I actually helped a client in the past with a similar issue. The solution I came up with was to use a Xalan JavaScript function to replace the named entity with it's numeric counterpart.

    I went ahead and tweaked my Xalan function to include all possible entities and updated your Format to test, it looks like that did the trick. I've attached your updated Format to this discussion. Specifically, scope out line 405 for usage example.

    Note: feel free to remove entities that are not necessary from the Xalan function if you wish. I got the list of entities from this article.

    Please let me know if you have any questions.

    Thanks!

  10. Ryan Griffith closed this discussion on 10 Nov, 2014 08:53 PM.

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

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM