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

  • Home
  • SEARCH
  • 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 3695426
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:36:59+00:00 2026-05-19T04:36:59+00:00

I am using XSLT to convert XML to HTML. I am having trouble figuring

  • 0

I am using XSLT to convert XML to HTML. I am having trouble figuring out how to deal with embedded XML nodes for formatting. For example, let’s say I have the XML element:

<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>

However, during XLST, the <i> tag gets ignored, so “Star Wars” is not italicized in the HTML output. Is there a relatively simple way to fix this?

test.xml:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
    <favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>
</favoriteMovies>

test.html.xsl:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" omit-xml-declaration="yes" />
    <xsl:template match="/">
      <html>
        <head />
          <body>
            <ul>
                <xsl:for-each select="favoriteMovies/favoriteMovie">
                    <li><xsl:value-of select="." /></li>
                </xsl:for-each>
            </ul>
          </body>
      </html>
    </xsl:template>
</xsl:stylesheet>
  • 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-19T04:37:00+00:00Added an answer on May 19, 2026 at 4:37 am

    However, during XLST, the <i> tag gets
    ignored, so “Star Wars” is not
    italicized in the HTML output. Is
    there a relatively simple way to fix
    this?

    Your problem is here:

    <ul>
      <xsl:for-each select="favoriteMovies/favoriteMovie">
        <li><xsl:value-of select="."/></li>
      </xsl:for-each>
    </ul>
    

    The <xsl:value-of> instruction is used to create a text node. In doing so it copies to the output the string value of the XPath expression specified in the select attribute of this XSLT instruction. The string value of an element is the concatenation of all its text-node descendents.

    So this is how you get the reported output.

    Solution:

    Use the <xsl:copy-of> instruction, which copies all the nodes that are specified in its select attribute:

    <ul>
      <xsl:for-each select="favoriteMovies/favoriteMovie">
        <li><xsl:copy-of select="node()"/></li>
      </xsl:for-each>
    </ul>
    

    Another solution, more alligned with the principles of XSLT avoids using <xsl:for-each> at all:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="/">
      <html>
        <head />
        <body>
         <xsl:apply-templates/>
        </body>
      </html>
     </xsl:template>
    
     <xsl:template match="/*">
      <ul>
       <xsl:apply-templates/>
      </ul>
     </xsl:template>
    
     <xsl:template match="favoriteMovie">
      <li><xsl:copy-of select="node()"/></li>
     </xsl:template>
    </xsl:stylesheet>
    

    When any of the two solutions defined above are applied to the provided XML document:

    <favoriteMovies>
        <favoriteMovie>the 
            <i>Star Wars</i> saga
        </favoriteMovie>
    </favoriteMovies>
    

    the wanted, correct result is produced:

    <html>
        <head/>
        <body>
            <ul>
                <li>the 
                    <i>Star Wars</i> saga
                </li>
            </ul>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.