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 8526979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:25:32+00:00 2026-06-11T08:25:32+00:00

Given an input XML document like this: <?xml version=1.0 encoding=utf-8?> <title> This contains an

  • 0

Given an input XML document like this:

<?xml version="1.0" encoding="utf-8"?>
<title> This contains an 'embedded' HTML document </title>
<document>
<html>
<head><title>HTML DOC</title></head>
<body>
Hello World
</body>
</html>
</document>
</root>

How I can extract that ‘inner’ HTML document; render it as CDATA and include in my output document ?

So the output document will be an HTML document; which contains a text-box showing the elements as text (so it will be displaying the ‘source-view’ of the inner document).

I have tried this:

<xsl:template match="document">
<xsl:value-of select="*"/>
</xsl:template>

But this only renders the Text Nodes.

I have tried this:

<xsl:template match="document">
<![CDATA[
<xsl:value-of select="*"/>
]]>
</xsl:template>

But this escapes the actual XSLT and I get:

&lt;xsl:value-of select="*"/&gt;

I have tried this:

<xsl:output method="xml" indent="yes" cdata-section-elements="document"/>
[...]
<xsl:template match="document">
<document>
<xsl:value-of select="*"/>
</document>
</xsl:template>

This does insert a CDATA section, but the output still contains just text (stripped elements):

<?xml version="1.0" encoding="UTF-8"?>
<html>
   <head>
      <title>My doc</title>
   </head>
   <body>
      <h1>Title: This contains an 'embedded' HTML document </h1>
      <document><![CDATA[
                                                HTML DOC

                                                                Hello World

                                ]]></document>
   </body>
</html>
  • 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-11T08:25:34+00:00Added an answer on June 11, 2026 at 8:25 am

    There are two confusions you need to clear up here.

    First, you probably want xsl:copy-of rather than xsl:value-of. The latter returns the string value of an element, the former returns a copy of the element.

    Second, the cdata-section-elements attribute on xsl:output affects the serialization of text nodes, but not of elements and attributes. One way to get what you want would be to serialize the HTML yourself, along the lines of the following (not tested):

    <xsl:template match="document/descendant::*">
      <xsl:value-of select="concat('&lt;', name())"/>
      <!--* attributes are left as an exercise for the reader ... *-->
      <xsl:text>&gt;</xsl:text>
      <xsl:apply-templates/>
      <xsl:value-of select="concat('&lt;/', name(), '>')"/>
    </xsl:template>
    

    But the quicker way would be something like the following solution (squeamish readers, stop reading now), pointed out to me by my friend Tommie Usdin. Drop the cdata-section-elements attribute from xsl:output and replace your template for the document element with:

    <xsl:template match="document">
      <document>
        <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
        <xsl:copy-of select="./html"/>
        <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
      </document>
    </xsl:template> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this code (C#, .NET 3.5 SP1): var doc = new XmlDocument(); doc.LoadXml(<?xml version=\1.0\?><root>
Given the input XML file: <acctInfo> <wfInfo> <aaa>1</aaa> <bbb>1</bbb> <ccc>1</ccc> <ddd>1</ddd> <eee>1</eee> </wfInfo> <acctInfo>
I am looking to transform a input xml given below <profile name=default> <color id=forecolor
So given this input string: =?ISO-8859-1?Q?TEST=2C_This_Is_A_Test_of_Some_Encoding=AE?= And this function: private string DecodeSubject(string input) {
How can I determine whether a given node is present in my input xml?
i am new to xquery. I have the following xml document : <?xml version=1.0
Given a xml file as input howto modify a attribute of a tag with
For a given xml, I need to generate a html table to represent the
I have rather large input XML files that must be converted to a given
I am attempting to compose a style sheet that, given an XML input (obviously)

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.