Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.
Reply With Quote
  #2 (permalink)  
Old October 6th, 2010, 10:58 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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?
Reply With Quote
  #3 (permalink)  
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:05 AM.


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