Java Tutorial/JSTL/XML Transformation

Материал из Java эксперт
Перейти к: навигация, поиск

Pass Parameter to XML Transformation

<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.ru/jstl/xml" prefix="x" %>
<c:import var="xml" url="students.xml" />
<c:import var="xslt" url="transformparam.xsl" />
<x:transform xml="${xml}" xslt="${xslt}">
<x:param name="bgColor" value="blue"/>
</x:transform>





Transform XML Data using JSTL

<%@taglib prefix="c" uri="http://java.sun.ru/jstl/core" %>
<%@taglib prefix="x" uri="http://java.sun.ru/jstl/xml" %>
<c:set var="xml">
  <paragraph>
     This document uses <bold>unusual</bold> markup,
     which we want to replace with <bold>HTML</bold>.
  </paragraph>
</c:set>
<c:set var="xsl">
  <?xml version="1.0"?>
  <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
  <xsl:template match="paragraph">
    <P><xsl:apply-templates/></p>
  </xsl:template>
  <xsl:template match="bold">
    <b><xsl:value-of select="."/></b>
  </xsl:template>
  </xsl:stylesheet>
</c:set>
<x:transform xml="${xml}" xslt="${xsl}"/>