Logo
4 Oct 2012 | 1 min. (110 words)

How to prevent self-closing elements in XSLT

If you are to put an element into XSLT without any child elements, the element will automatically close itself. Therefore, if you have the following markup:

<div class="clear"></div>

XSLT will automatically render this as:

<div class="clear" />

This is fine for most elements, however some elements such as <div> will behave differently if they are self-closed.

A good way of preventing this from happening is to add an empty value into the <div> element like so:

<div class="clear"><xsl:value-of select="''"/></div>

This will tell the XSLT rendering engine that there is some form of content inside the element, and therefore not to close itself. The rendered output would then be:

<div class="clear"></div>
html xslt
Twitter Facebook

Creating a new rule for a CSS class in jQuery

…

Using jQuery callback functions

…

Related Links

  • LinkedIn
  • Twitter: @curtcode
  • Stack Overflow
  • GitHub: @curtiscde

Stack Exchange

profile for Curtis on Stack Exchange, a network of free, community-driven Q&A sites
Follow @curtiscde

Recent Posts

  • Displaying latest posts on your GitHub profile
  • Using Codecov within a monorepo
  • Displaying Strava stats using webhooks & GitHub Actions
  • Filtering duplicate data points on Chart.js
  • Next.js Typerite Template Boilerplate
Theme Bleak by zutrinken Published with Hugo
Menu