p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   XML to JSF (http://p2p.wrox.com/showthread.php?t=81161)

prss October 6th, 2010 10:08 AM

XML to JSF
 
I've been searching over the internet a solution to my problem but I couldn't find any so far. I want to transform a XML file in a JSF page. I've created a XSL file and parsed it using Xalan for Java. The problem is that the file generated by the parser always include a namespace definition inside my component tag, for example, instead of getting as outcome <h:input id="input1"/> I get <h:inputText id="input1" xmlns:h="http://java.sun.com/jsf/html"/>.
I'd like to know how should I proceed to suppress this namespace definition, using Xalan or other API.


Below are my xsl and my generated jsp file:

<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:text disable-output-escaping="yes">
&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"%>
&lt;%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
&lt;%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
</xsl:text>

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

</xsl:template>

</xsl:stylesheet>

-------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<br/><br/><h:inputText id="input1" xmlns:h="http://java.sun.com/jsf/html"/>




Thanks in advance!
Paulo S.

samjudson October 6th, 2010 10:58 AM

You can't suppress the namespace declaration, because that would mean that the XML document being produced was invalid, which isn't allowed.

prss October 6th, 2010 11:44 AM

I managed to find a solution. I just dropped the namespace declaration in the beginning of the xsl file and I replaced the < signal for &lt;
The problem I have now is that after these modifications the follow expression {$id} doesn't work any more. My generated jsp file contains <h:inputText id="$id" /> instead of <h:inputText id="input1" />
I tried to write the expression <xsl:value-of select="input_text/@id" /> but despite of bringing the correct value (input1) it breaks the line resulting in something like that:
<h:inputText id= />
input1

Can anyone help me to solve this issue?

Follow my files:

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

<xsl:template match="/">

<xsl:text disable-output-escaping="yes">
&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"%>
&lt;%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
&lt;%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
</xsl:text>

<xsl:for-each select="questionario/componente">
<br />
<xsl:if test="attribute::nome = 'input'">
<xsl:variable name="label">
<xsl:value-of select="input_text/@label" />
</xsl:variable>
<br />
<xsl:variable name="id">
<xsl:value-of select="input_text/@id" />
</xsl:variable>
<xsl:text disable-output-escaping="yes">
&lt;h:inputText id="$id" /&gt;
</xsl:text>
</xsl:if>
</xsl:for-each>

</xsl:template>

</xsl:stylesheet>


------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<br/><br/>
<h:inputText id="$id" />

Thanks again,
Paulo S.


All times are GMT -4. The time now is 08:27 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.