XHTML XML XSLT and the Img tag

Posted on 2004-11-09
Last Modified: 2013-12-16
I am trying to make my code compliant as XHTML.

The validator at had trouble validating a page and when I looked at the code I found why. The output is as follows:

<div><img src="closed.gif" alt="close" id="a1">Details</div>

The problem is that there is no close for the image tag. But if you look at the XSL there is a problem. Within the div tags there is a image start tag and then an xsl attribute to set the ID for the image. Then there needs to be an image close tag but that does not exist in the HTML language, my code cannot be compliant without it. What a dilemma!

<div><img src="closed.gif"><xsl:attribute name="id">a<xsl:value-of select="@Menu"></xsl:value-of></xsl:attribute></img><xsl:value-of select="@Desc"/></div>      
Question by:blindbull
    LVL 9

    Expert Comment

    Close the img tag Like this
    <div><img src="closed.gif" alt="close" id="a1" />Details</div>

    LVL 5

    Expert Comment

    in XSLT the image tag is closed but the result displays different..
    normally XSLT element transformations without any "childNodes" will result in an empty element <element />

    what kind of XSLT processor is used?! :)

    (the "alt" attribute is mandatory on an img element in XHTML)
    LVL 5

    Accepted Solution

    Change the output to output strict XHTML in the XSL stylesheet

    <!-- Force the output to be strict XHTML -->
          <xsl:output method="xml" indent="yes" encoding="iso-8859-1"
                doctype-public="-//W3C//DTD XHTML 1.0//EN"

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure ( It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now