Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8677679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:31:28+00:00 2026-06-12T20:31:28+00:00

I have an XML file with all the nodes that contain information are in

  • 0

I have an XML file with all the nodes that contain information are in CDATA. These information are possibly formatted with some HTML tags, something like this:

<EventList>
    <Text><![CDATA[<p>Some text <i>is</i> formatted! This is a character entity &#39;</p>]]></Text>
    <ShortText><![CDATA[Some other is only plain]]></ShortText>
    <!-- others more -->
</EventList>

I want to transform this with XSLT in a (X)HTML page:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output 
  method="html" 
  doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" 
  media-type="application/xhtml+xml" 
  encoding="utf-8" 
  omit-xml-declaration="yes" 
  indent="no"
/>
  <xsl:template match="Text">
    <h2><xsl:copy-of select="text()"/></h2>
  </xsl:template>

  <xsl:template match="ShortText">
    <div><xsl:copy-of select="."/></div>
  </xsl:template>
</xsl:stylesheet>

But appling this transformation produce a strange behavior. The HTML tags I did put in the XSLT are parsed and interpreted correctly from the browser, but the tags inside the CDATA are stripped of the <, > and & char, producing this output:

<h2>pSome text iis/i formatted!  This is a character entity #39;/p</h2>
<div>Some other is only plain</div>

At first it looked something like an issue in the <xsl:output> definition, but I’m still stuck on this. I’ve tried to use the shorthand XPath . and the function text() but the output it’s the same.
Any suggestion is appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:31:29+00:00Added an answer on June 12, 2026 at 8:31 pm

    Your XML says that the content of the Text element is a string of characters with no markup in it, which happens to contain a number of occurrences of XML delimiters like left angle bracket and ampersand. Your stylesheet says to write that string of characters out as a string of characters, without markup, so a conforming HTML processor will do so, producing as output something like

    <H2 xmlns="http://www.w3.org/1999/xhtml"
      >&lt;p&gt;Some text &lt;i&gt;is&lt;/i&gt; formatted! 
      This is a character entity &amp;#39;&lt;/p&gt;</h2>
    <div xmlns="http://www.w3.org/1999/xhtml"
      ><ShortText xmlns="">Some other is only plain</ShortText></div>
    

    I’ve introduced line breaks to keep the lines shorter. This is not what you are showing as your output, which is suggestive in itself.

    The easiest way to get better results is to make your XML start telling the truth about the data: if you want the Text element to contain some HTML elements like p and i, then make it do so, and then use an identity transform on that part of your data.

    If the broken design of this XML is something you are stuck with, then you can work around the damage by using the disable-output-escaping attribute on the xsl:value-of element. (Warning: the need to use disable-output-escaping is almost always a signal that something is wrong in the design.) This version of your template for Text produces output in which the string data of the input is written out as XHTML markup:

    <xsl:template match="Text">
      <h2><xsl:value-of select="string(.)" 
                        disable-output-escaping="yes"/></h2>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an xml file that contains lots of different nodes. some in particularly
I have a map that reads an XML file; it's all very simple and
I have an XML file that I have parsed and have put the information
I have a large XML file, in which every nodes requires a CDATA tag.
I have an XML file and I need to extract testname from all the
I have defined a local mirror for all repositories in the settings.xml file: <mirror>
I have set up multiple targets in a single xml file. I expect all
What is the easiest way to convert xml to html? I have xml file
I have an XML file from which I am parsing some content to display
I have an XML file that looks like <?xml version=1.0> <playlist> <name>My Playlist</name> <song>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.