JSTL - XML <x:transform> Tag

The <x:transform> tag applies an XSL transformation on an XML document.


The <x:transform> tag has the following attributes −

Attribute Description Required Default
doc Source XML document for the XSLT transformation No Body
docSystemId URI of the original XML document No None
xslt XSLT stylesheet providing transformation instructions Yes None
xsltSystemId URI of the original XSLT document No None
result Result object to accept the transformation's result No Print to page
var Variable that is set to the transformed XML document No Print to page
scope Scope of the variable to expose the transformation's result No None


Consider the following XSLT stylesheet style.xsl

<?xml version = "1.0"?>
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" 
   version = "1.0">

<xsl:output method = "html" indent = "yes"/>
   <xsl:template match = "/">

   <xsl:template match = "books">
      <table border = "1" width = "100%">
         <xsl:for-each select = "book">
                  <i><xsl:value-of select = "name"/></i>
                  <xsl:value-of select = "author"/>
                  <xsl:value-of select = "price"/>


Now consider the following JSP file −

<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix = "x" uri = "http://java.sun.com/jsp/jstl/xml" %>

      <title>JSTL x:transform Tags</title>

      <h3>Books Info:</h3>
      <c:set var = "xmltext">
               <name>Padam History</name>
               <name>Great Mistry</name>

      <c:import url = "http://localhost:8080/style.xsl" var = "xslt"/>
      <x:transform xml = "${xmltext}" xslt = "${xslt}"/>


You will receive the following result −

Books Info:

Padam History



Great Mistry


Kickstart Your Career

Get certified by completing the course

Get Started