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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:55:15+00:00 2026-05-30T13:55:15+00:00

I am using XSLT to remove unnecessary attributes from some nodes in a file.

  • 0

I am using XSLT to remove unnecessary attributes from some nodes in a file. Nodes which should not be transformed use the following simple template:

<!-- Copy everything else over -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

However, I have found that some nodes are loosing escaped characters contained in their attribute values.

For example, this input:

<field value="Lei Complementar No. 116/2003, Art. 6, &#167; 2&#186;, I."/>

end up looking like this:

<field value="Lei Complementar No. 116/2003, Art. 6, § 2º, I."/>

How can I prevent this unwanted transformation?

  • 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-05-30T13:55:16+00:00Added an answer on May 30, 2026 at 1:55 pm

    I. XSLT 1.0 solution:

    Just add this attribute to xsl:output:

    encoding="us-ascii"
    

    This causes any non-ascii character to be rendered with its character code.

    However, you may still get different outputs, such as:

    <field value="Lei Complementar No. 116/2003, Art. 6, &#167; 2&#186;, I."/>
    

    and

    <field value="Lei Complementar No. 116/2003, Art. 6, &#xA7; 2&#xBA;, I." />
    

    And, of course, all of these three are just different represenatations of the same string of (unicode) characters.

    II. XSLT 2.0 solution:

    This uses the <xsl:character-map> instruction and must always produce the same output:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xsl:output omit-xml-declaration="yes"
       indent="yes" use-character-maps="chmEscapes"/>
    
     <xsl:character-map name="chmEscapes">
      <xsl:output-character character="&#167;"
                            string="&amp;#167"/>
      <xsl:output-character character="&#186;"
                            string="&amp;#186"/>
     </xsl:character-map>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the provided XML document:

    <field value="Lei Complementar No. 116/2003, Art. 6, &#167; 2&#186;, I."/>
    

    the wanted, correct result is produced:

    <field value="Lei Complementar No. 116/2003, Art. 6, &#167 2&#186, I."/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to remove nodes from an XML file. Using just one XSLT
I am trying to remove the attribute xmlns=http://webdev2003.test.com from the following xml using xsl/xslt,
I looked at How to remove duplicate XML nodes using XSLT and other related
Is it possible to remove xml attributes from XSLT AND work with the resulting
I'm not an XSLT wizard. I have the current XSLT i'm using to remove
is there a way to convert all nodes' attributes into child Nodes using XSLT
I'm using XSLT to process my ASP.Net web.config file to insert some extra log4net
How can I using XSLT, select only some xml tags from my input xml
I'm using XSLT 1.0 an want to transform an XML file. It works fine
I'm using xslt do display Solr response in html, my xsl file is in

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.