Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 6th, 2010, 10:08 AM
Registered User
 
Join Date: Oct 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
 
Old October 6th, 2010, 10:58 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You can't suppress the namespace declaration, because that would mean that the XML document being produced was invalid, which isn't allowed.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old October 6th, 2010, 11:44 AM
Registered User
 
Join Date: Oct 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Building Web 2.0 UIs with JSF, Realtime Updates with JSF & Ajax Push Taught at GIDS Shaguf J2EE 0 March 4th, 2010 07:54 AM
Building Web 2.0 UIs with JSF, Realtime Updates with JSF & Ajax Push Taught at GIDS Shaguf J2EE 0 March 4th, 2010 07:53 AM
Using XSLT to tranform XML into JSF pdimilla XSLT 4 July 3rd, 2009 03:50 AM
JSF l1234567890 JSP Basics 0 October 3rd, 2005 09:34 PM
What about JSF ? bergeroy BOOK: Expert One-on-One J2EE Design and Development 1 April 8th, 2004 01:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.