Index: src/main/java/org/hippoecm/hst/tag/HeadContributionsTag.java
===================================================================
--- src/main/java/org/hippoecm/hst/tag/HeadContributionsTag.java	(revision 21358)
+++ src/main/java/org/hippoecm/hst/tag/HeadContributionsTag.java	(revision )
@@ -35,83 +35,84 @@
 import org.w3c.dom.Element;
 
 public class HeadContributionsTag extends TagSupport {
-    
+
     static Logger logger = LoggerFactory.getLogger(HeadContributionsTag.class);
 
     private static final long serialVersionUID = 1L;
-    
+
     private boolean xhtml;
-    
+
     /**
      * Comma separated category includes list
      */
     private Set<String> categoryIncludes;
-    
+
     /**
      * Comma separated category excludes list
      */
     private Set<String> categoryExcludes;
-    
+
     public HeadContributionsTag() {
     }
-    
+
     public void setXhtml(boolean xhtml) {
         this.xhtml = xhtml;
     }
-    
+
     public boolean getXhtml() {
         return xhtml;
     }
-    
+
     public void setCategoryIncludes(String categoryIncludes) {
         this.categoryIncludes = new HashSet<String>(Arrays.asList(StringUtils.split(categoryIncludes, ", \t")));
     }
-    
+
     public String getCategoryIncludes() {
         if (categoryIncludes != null) {
             StringUtils.join(categoryIncludes, ", ");
         }
-        
+
         return null;
     }
-    
+
     public void setCategoryExcludes(String categoryExcludes) {
         this.categoryExcludes = new HashSet<String>(Arrays.asList(StringUtils.split(categoryExcludes, ", \t")));
     }
-    
+
     public String getCategoryExcludes() {
         if (categoryExcludes != null) {
             StringUtils.join(categoryExcludes, ", ");
         }
-        
+
         return null;
     }
-    
+
     public int doEndTag() throws JspException {
         // if hstRequest is retrieved, then this servlet has been dispatched by hst component.
         HstResponse hstResponse = (HstResponse) pageContext.getRequest().getAttribute(ContainerConstants.HST_RESPONSE);
-        
+
         if (hstResponse == null && pageContext.getResponse() instanceof HstResponse) {
             hstResponse = (HstResponse) pageContext.getResponse();
         }
-        
+
         if (hstResponse != null) {
             List<Element> headElements = hstResponse.getHeadElements();
-            
+
             if (headElements != null && !headElements.isEmpty()) {
                 try {
                     boolean categoryIncludesEmpty = (categoryIncludes == null || categoryIncludes.isEmpty());
                     boolean categoryExcludesEmpty = (categoryExcludes == null || categoryExcludes.isEmpty());
-                    
+
                     if (!categoryIncludesEmpty || !categoryExcludesEmpty) {
                         for (Element headElement : headElements) {
                             boolean skip = true;
-                            
+
-                            String category = headElement.getAttribute(ContainerConstants.HEAD_ELEMENT_CONTRIBUTION_CATEGORY_HINT_ATTRIBUTE);
+                            String category = headElement
+                                    .getAttribute(ContainerConstants.HEAD_ELEMENT_CONTRIBUTION_CATEGORY_HINT_ATTRIBUTE);
                             if (category != null && "".equals(category)) {
                                 category = null;
                             }
-                            
+
                             if (!categoryIncludesEmpty) {
                                 if (category != null && categoryIncludes.contains(category)) {
                                     skip = false;
@@ -126,37 +127,43 @@
                                     skip = categoryExcludes.contains(category);
                                 }
                             }
-                            
+
                             if (skip) {
                                 continue;
                             }
-                            
+
                             HeadElement outHeadElement = new HeadElementImpl(headElement);
-                            if (outHeadElement.hasAttribute(ContainerConstants.HEAD_ELEMENT_CONTRIBUTION_CATEGORY_HINT_ATTRIBUTE)) {
-                                outHeadElement.removeAttribute(ContainerConstants.HEAD_ELEMENT_CONTRIBUTION_CATEGORY_HINT_ATTRIBUTE);
+                            if (outHeadElement.hasAttribute(
+                                    ContainerConstants.HEAD_ELEMENT_CONTRIBUTION_CATEGORY_HINT_ATTRIBUTE)) {
+                                outHeadElement.removeAttribute(
+                                        ContainerConstants.HEAD_ELEMENT_CONTRIBUTION_CATEGORY_HINT_ATTRIBUTE);
                             }
-                            
+
                             if (xhtml) {
-                                pageContext.getOut().println(HeadElementUtils.toXhtmlString(outHeadElement));
+                                pageContext.getOut().println(
+                                        HeadElementUtils.toXhtmlString(outHeadElement, isContentTypeTextHtml()));
                             } else {
                                 pageContext.getOut().println(HeadElementUtils.toHtmlString(outHeadElement));
                             }
-                            
+
                             pageContext.getOut().flush();
                         }
                     } else {
                         for (Element headElement : headElements) {
                             HeadElement outHeadElement = new HeadElementImpl(headElement);
-                            if (outHeadElement.hasAttribute(ContainerConstants.HEAD_ELEMENT_CONTRIBUTION_CATEGORY_HINT_ATTRIBUTE)) {
-                                outHeadElement.removeAttribute(ContainerConstants.HEAD_ELEMENT_CONTRIBUTION_CATEGORY_HINT_ATTRIBUTE);
+                            if (outHeadElement.hasAttribute(
+                                    ContainerConstants.HEAD_ELEMENT_CONTRIBUTION_CATEGORY_HINT_ATTRIBUTE)) {
+                                outHeadElement.removeAttribute(
+                                        ContainerConstants.HEAD_ELEMENT_CONTRIBUTION_CATEGORY_HINT_ATTRIBUTE);
                             }
-                            
+
                             if (xhtml) {
-                                pageContext.getOut().println(HeadElementUtils.toXhtmlString(outHeadElement));
+                                pageContext.getOut().println(
+                                        HeadElementUtils.toXhtmlString(outHeadElement, isContentTypeTextHtml()));
                             } else {
                                 pageContext.getOut().println(HeadElementUtils.toHtmlString(outHeadElement));
                             }
-                            
+
                             pageContext.getOut().flush();
                         }
                     }
@@ -165,8 +172,11 @@
                 }
             }
         }
-        
+
         return SKIP_BODY;
     }
-    
+
+    private boolean isContentTypeTextHtml() {
+        return pageContext.getResponse().getContentType().startsWith("text/html");
-}
+    }
+}
