p2p.wrox.com Forums

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

pdimilla July 1st, 2009 04:20 PM

Using XSLT to tranform XML into JSF

I am trying to find a example of using XSLT to transform XML into JSF. I've seen a couple of threads in other forums that indicate that this is easy; however, when I've tried it I've run into problems. Searching the web has yielded no good examples. In particular, I am having trouble with the taglibs. Here's my stylesheet:


<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
extension-element-prefixes="b64 dep">

<xsl:template match="TAG">
<xsl:text disable-output-escaping="yes">
&lt;%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
&lt;%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
&lt;%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
&lt;%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<img src="../hmss/images/MedNet50.jpg" />
<f:facet name="header">
<h:outputText value="tag id"/>
<h:outputText value="<xsl:value-of select="tagid"/>"/>
<f:facet name="header">
<h:outputText value="mac address"/>
<h:outputText value="<xsl:value-of select="mac"/>"/>
<f:facet name="header">
<h:outputText value="map name"/>
<h:outputText value="<xsl:value-of select="posmapname"/>"/>
<f:facet name="header">
<h:outputText value="timestamp"/>
<h:outputText value="<xsl:value-of select="postimestamp"/>"/>
<xsl:variable name="data" select="data_b"/>
<xsl:value-of select="b64:decodeToFile($data,'map.png')"/>
<img src="{dep:deployFile('map.png')}" />


I am using the XALAN processor. My operating system is Windows XP. My problem is strictly with the taglibs. Any help is appreciated.


mhkay July 1st, 2009 07:05 PM

You say you're having trouble but you don't say what trouble you are having.

Producing output in a non-XML format will always be a bit tricky, but it can usually be achieved using disable-output-escaping provided it's supported in your particular environment. This may depend on how you run the transformation, e.g. it may not work when writing to a DOM result.

This code is nonsense:

<h:outputText value="<xsl:value-of select="tagid"/>"/>

because it means your stylesheet isn't even well-formed XML. It should be

<h:outputText value="{tagid"}"/>

This of course is nothing to do with the taglibs.

pdimilla July 2nd, 2009 06:38 PM

I just assumed it was taglib problem because I saw the following exception in my app log:


org.xml.sax.SAXParseException: The prefix "h" for element "h:dataTable" is not bound.        org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)        org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)        org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:920)        org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:774)
I see that the problem goes far beyond that. And, yes, I believe I am writing to a DOM result.

Thank you for your help.

mhkay July 3rd, 2009 03:50 AM

>The prefix "h" for element "h:dataTable" is not bound.

That's not a taglib problem, it's a basic XML problem. In XSLT, as in XML, you need to declare your namespace prefixes.

Unfortunately I think you're trying to tackle quite a tricky XSLT problem when you haven't learnt enough of the basics to tackle simple problems. I really would recommend reading some good books or tutorials and starting with easier problems. You can't expect to jump in a car and start driving without having some lessons first.

mhkay July 3rd, 2009 03:50 AM

Oh, and by the way: if you get an error message and don't understand it, then it helps to post the error message.

All times are GMT -4. The time now is 12:34 AM.

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