views:

40

answers:

2

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"/&gt; 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?

A: 

I've never done it like this, but in theory, when you see JSF tags unparsed in the resulting XHTML output, then it simply means that the FacesServlet hasn't done its job. You need to ensure that it is registered in web.xml on a specified url-pattern and that the request URL (as in browser address bar) matches the url-pattern of the FacesServlet. If it is for example *.jsf, then you shouldn't open the JSP page by http://example.com/page.jsp but by http://example.com/page.jsf.


Update: as said, I've never done like that and I doubt if it will ever work in theory. However, from experience I can tell that the approach as described in this answer works. The XSL should have done its job before the view is been passed through the FacesServlet. Right now you're trying to do it simultaneously.

BalusC
The url pattern is right, the problem is in the transformation process. When I tried to make such process in the bean I got <h:inputText id="input_1" xmlns:h="http://java.sun.com/jsf/html"/> too, but I could treat it as a string and suppress this unwanted content. But I couldn't write the content of the string in the jsf page and get it to update its content mid-on-fly.
Paulo S.
A: 

(moved update back into question, you should delete this "answer")

Paulo S.