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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:06:11+00:00 2026-06-11T21:06:11+00:00

I’m using XSLT to extract some HTML content with special characters (like   )

  • 0

I’m using XSLT to extract some HTML content with special characters (like &nbsp;) from an XML file. The content is stored in <content> nodes. I have defined most special characters like this: <!ENTITY nbsp "&#160;">, so this expression works perfectly fine:

<xsl:copy-of select="content" disable-output-escaping="yes"/>

Now, I want to add target="_blank" to every link found within that content. This is the solution I came up with:

<xsl:template match="a" mode="html">
    <a>
        <xsl:attribute name="href"><xsl:value-of select="@*"/></xsl:attribute>
        <xsl:attribute name="target">_blank</xsl:attribute>
        <xsl:apply-templates select="text()|* "/>
    </a>
</xsl:template>

And instead of the “copy-of” element I use this:

<xsl:apply-templates select="content" mode="html"/>

Now all those special characters (and nbsp too) disappeared from the output. How do I keep them? Seems like disable-output-escaping="yes" doesn’t help here.

Ok, I’m using the XSLTProcessor class in PHP. The disable-output-escaping attribute didn’t give an error actually, but when I removed it, the output was the same, with all the nbsp’s, so it didn’t matter.


UPD. With the XSL template I have shown before, my input sample:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE page SYSTEM "html-entities.xsl">
<content>There is a&nbsp;non-breaking <a href="http://localhost">space</a> inside.</content>

html-entities.xsl:

<?xml version="1.0" encoding="UTF-8"?>
<!ENTITY nbsp "&#160;">

PHP code:

$xp = new XSLTProcessor();
$xsl = new DOMDocument();
$xsl->load($xsl_filename);
$xp->importStylesheet($xsl);
$xml_doc = new DOMDocument();
$xml_doc->resolveExternals = true;
$xml_doc->load($xml_filename);
$html = $xp->transformToXML($xml_doc);

My current output:

There is anon-breaking <a href="http://localhost" target="_blank">space</a> inside.

My desired output:

There is a&nbsp;non-breaking <a href="http://localhost" target="_blank">space</a> inside.

  • 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-11T21:06:12+00:00Added an answer on June 11, 2026 at 9:06 pm

    Basically whether the source code of the input XML document has a character reference like &#160; or an entity reference like &nbsp; or such a character literally does not matter to XSLT and does not make a difference how the input is processed and how the output looks; basically XSLT operates on a tree with Unicode characters stored in text nodes. At least that is the theory, your PHP code seems to work with a DOM tree model which might store entity reference nodes but even then for XSLT that shouldn’t matter. In the input tree there should be text nodes containing Unicode characters (one if which could be the non-breaking space character with Unicode 160) and if you copy such a text to the output the result tree has a text node with the same Unicode characters.

    For the output method html some XSLT processors (Saxon 6.5.5 for instance) might do you the favour to ensure characters defined as entities in HTML are serialized with the corresponding entity reference but even if they don’t do that the serialization of the result tree should be a file with the proper Unicode characters, encoded as directed by the encoding attribute of the xsl:output element.

    Your current result which completely drops the character (e.g. There is anon-breaking) does not make sense to me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.