XSLT, JSTL e JSF

Posted by Paulo S. on Stack Overflow See other posts from Stack Overflow or by Paulo S.
Published on 2010-10-08T14:47:28Z Indexed on 2011/01/14 14:53 UTC
Read the original article Hit count: 305

Filed under:
|
|
|

I have a xml file which I want to transform in a jsf code page. To do that I've created a xsl file.

xml:

<?xml version='1.0' encoding='ISO-8859-1'?>
<questionario xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
              xsi:noNamespaceSchemaLocation='Schema2.xsd'>
    <componente nome='input'>
         <id>input1</id>
    </componente>
    <componente nome='input'>
         <id>input2</id>
    </componente>
</questionario>

code:

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

<c:set var="xml" value="${questionarioXSLBean.xml}"/>

<c:set var="xsl">
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    exclude-result-prefixes="f h">

    <xsl:template match="/">
  <xsl:for-each select="questionario/componente">
   <xsl:if test="attribute::nome = 'input'">
    <xsl:variable name="id">
     <xsl:value-of select="id" />
    </xsl:variable>
    <h:inputText id="{$id}"/>
   </xsl:if>
  </xsl:for-each>

 </xsl:template>

</xsl:stylesheet>
</c:set>

<x:transform xml="${xml}" xslt="${xsl}" />

The problem is that nothing is shown in my screen because the generated code for <h:inputText id="input1"/> is <h:inputText id="input_1" xmlns:h="http://java.sun.com/jsf/html"/> how can I replace the xmlns:h="http://java.sun.com/jsf/html" or suppress it.

Thanks!


Update: Let me clarify what I want to do. I want to generate a jsf page dynamically depending on the attributes of a xml file, for instance, 2 input texts, 3 check boxes, etc. To make the transformation to jsf I thought in two approaches, one using jstl and another using xslt. The problem with the former is that I couldn't integrate jstl with jsf code (to set jsf components attributes using jstl variables) and with the last approach, I'm facing the problem described above.I wouldn't like to create components in java (UIComponents). Any suggestions?

© Stack Overflow or respective owner

Related posts about jsf

Related posts about jstl