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

The Archive Base Latest Questions

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

Suppose I have a source example document like this: <html> <b><i><u>TestBIU</u></i></b> <i><b><u>TestIBU</u></b></i> <i><u><b>TestIUB</b></u></i> <b><u><i>TestBUI</i></u></b>

  • 0

Suppose I have a source example document like this:

<html>
  <b><i><u>TestBIU</u></i></b>
  <i><b><u>TestIBU</u></b></i>
  <i><u><b>TestIUB</b></u></i>
  <b><u><i>TestBUI</i></u></b>
  <u><i><b>TestUIB</b></i></u>
  <u><b><i>TestUBI</i></b></u>
  <u>TestU</u>
  <i>TestI</i>
  <b>TestB</b>
  <u><b>TestUB</b></u>
</html>

I need a XSLT-Template that produces this:

<html>
  <b><i>TestBIU</i></b>
  <i><b>TestIBU</b></i>
  <i><b>TestIUB</b></i>
  <b><i>TestBUI</i></b>
  <i><b>TestUIB</b></i>
  <b><i>TestUBI</i></b>
  <u>TestU</u>
  <i>TestI</i>
  <b>TestB</b>
  <b>TestUB</b>
</html>

So, it should remove the underline tag when it occurs in combination with italic and/or bold tags. When only underlined, it should remain.
Any ideas how to solve this particular problem?

Here is my attempt, but if fails for TestUIB and TestUBI:

<xsl:template match="/">
    <html>
    <xsl:apply-templates />
    </html>
</xsl:template>
<xsl:template match="b/u">
      <xsl:apply-templates />
</xsl:template>
<xsl:template match="i/u">    
      <xsl:apply-templates />
</xsl:template>
<xsl:template match="u/i">
  <i><xsl:apply-templates /></i>
</xsl:template> 
<xsl:template match="u/b">
    <b><xsl:apply-templates /></b>
</xsl:template>    
<xsl:template match="b | u | i">
    <xsl:copy>
        <xsl:apply-templates select="* | text()"/>
    </xsl:copy>
</xsl:template>
  • 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-14T11:31:13+00:00Added an answer on June 14, 2026 at 11:31 am

    Try this:

    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    
    <xsl:template match="@*|node()">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:template>
    
    <xsl:template match="u[ancestor::b | ancestor::i | descendant::b | descendant::i]">
        <xsl:apply-templates />
    </xsl:template>
    
    </xsl:stylesheet>
    

    It produces the following output to your sample:

    <html>
        <b><i>TestBIU</i></b>
        <i><b>TestIBU</b></i>
        <i><b>TestIUB</b></i>
        <b><i>TestBUI</i></b>
        <i><b>TestUIB</b></i>
        <b><i>TestUBI</i></b>
        <u>TestU</u>
        <i>TestI</i>
        <b>TestB</b>
        <b>TestUB</b>
    </html>
    

    Description: In my solution I’m using identity transform that copies everything node by node and attribute by attribute. The second template intercepts all <u> HTML tags that have <i> or <b> amongst their ancestors or descendants. When such situation occurs, we do not copy the tag, but only invoke apply-templates which will take care of its children.

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

Sidebar

Related Questions

Suppose we have this example: http://techdroid.kbeanie.com/2009/07/custom-listview-for-android.html with source code available here: http://code.google.com/p/myandroidwidgets/source/browse/trunk/Phonebook/src/com/abeanie/ How can
Suppose I have some javascript code like this: function Person(){} var pro=Person.prototype; pro[setName]=function(){} pro[setAge]=function(){}
Suppose I have Dictionary like this: Dictionary<string, string> values = new Dictionary<string, string>() {
Suppose I have a source file open and I launch a shell. I can
Suppose I have a source file that is 18218 bytes. I open the file
Let's suppose we have an open source project running in a server. Is there
Suppose I have an object file ( source.o ) without function main . a
Suppose I have a VC++ project containing number of Source (.cpp) files (e.g. 5),
Suppose I have two Java projects in Maven / Eclipse: An open source application
Suppose I have two lists that holds the list of source file names and

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.