You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by John Hicks <ja...@gulfbridge.net> on 2002/09/25 10:40:13 UTC

JSTL XML x:transform and x:out fetch no data

Hi All--

I've been using JSTL for some time now but am only now 
venturing into the XML/XSL part of it. All seems to work 
fine with just XML, but as soon as I add XSL, I run into 
problems.

My immediate goal is to use JSTL's XML library to replicate 
the following page:

http://gulfbridge.com/xmlGoal.html

Using only XML (no XSL), I was able to get x:parse and 
x:out to work just fine to copy straight text from a simple 
XML file:

http://gulfbridge.com/java/xmlTarget1.jsp

but as soon as I tried to use XSLT and the x:transform tag, 
I ran into problems:

http://gulfbridge.com/java/xmlTarget.jsp

(As you can see, nothing is being retrieved by x:out.)

You can view my source files here:

http://gulfbridge.com/tomcatSource/
http://gulfbridge.com/tomcatSource/xmlTarget.jsp
http://gulfbridge.com/tomcatSource/xmlSource.xml
http://gulfbridge.com/tomcatSource/xmlXsl.xsl

There's not much documentation on how to use x:transform 
but I found an example of it in Transform.jsp in the JSTL 
examples:

http://gulfbridge.com/JSTL-examples/xml/
http://gulfbridge.com/JSTL-examples/xml/Transform.jsp

where I found the following excerpt:

<x:transform xml="${xml}" xslt="${xsl}" var="doc"/>
<x:out select="$doc//h1"/>

Any ideas on why x:transform and x:out aren't working in my 
case?

TIA,

--John Hicks

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL XML x:transform and x:out fetch no data

Posted by Mauro Daniel Ardolino <ma...@altersoft.com.ar>.
Hello!
I'm using the XSL taglib to do something like this.  I will migrate to
JSTL because someone before (see previous mails) told me that XSL taglib
was out-of-date.
Try XSL taglib meanwhile...it works fine.
Then if I have success on migrating I'll tell you how.

Luck!

Mauro

On Wed, 25 Sep 2002, John Hicks wrote:

> Hi All--
> 
> I've been using JSTL for some time now but am only now 
> venturing into the XML/XSL part of it. All seems to work 
> fine with just XML, but as soon as I add XSL, I run into 
> problems.
> 
> My immediate goal is to use JSTL's XML library to replicate 
> the following page:
> 
> http://gulfbridge.com/xmlGoal.html
> 
> Using only XML (no XSL), I was able to get x:parse and 
> x:out to work just fine to copy straight text from a simple 
> XML file:
> 
> http://gulfbridge.com/java/xmlTarget1.jsp
> 
> but as soon as I tried to use XSLT and the x:transform tag, 
> I ran into problems:
> 
> http://gulfbridge.com/java/xmlTarget.jsp
> 
> (As you can see, nothing is being retrieved by x:out.)
> 
> You can view my source files here:
> 
> http://gulfbridge.com/tomcatSource/
> http://gulfbridge.com/tomcatSource/xmlTarget.jsp
> http://gulfbridge.com/tomcatSource/xmlSource.xml
> http://gulfbridge.com/tomcatSource/xmlXsl.xsl
> 
> There's not much documentation on how to use x:transform 
> but I found an example of it in Transform.jsp in the JSTL 
> examples:
> 
> http://gulfbridge.com/JSTL-examples/xml/
> http://gulfbridge.com/JSTL-examples/xml/Transform.jsp
> 
> where I found the following excerpt:
> 
> <x:transform xml="${xml}" xslt="${xsl}" var="doc"/>
> <x:out select="$doc//h1"/>
> 
> Any ideas on why x:transform and x:out aren't working in my 
> case?
> 
> TIA,
> 
> --John Hicks
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 

-- 
Ing.Mauro Daniel Ardolino
Departamento de Desarrollo y Servicios
Altersoft
Billinghurst 1599 - Piso 9
C1425DTE - Capital Federal
Tel/Fax: 4821-3376 / 4822-8759
mailto: mauro@altersoft.com.ar
website: http://www.altersoft.com.ar


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL XML x:transform and x:out work, but not together (was: x:transform and x:out fetch no data)

Posted by Shawn Bayern <ba...@essentially.net>.
On Thu, 26 Sep 2002, John Hicks wrote:

> Thanks to Shawn for clueing me in on the architecture of the
> x:transform and x:out tags. I've revised my test files and now x:out,
> with properly addressed select values, does indeed output actual data
> after a transform.
> 
> The only problem is: x:out doesn't output all the transformed output.
> It strips any tags generated by the transform and only outputs plain
> text.
> 
> Yet if I use a simple x:transform tag instead of x:out, the newly
> generated tags *are* there.

This is entirely expected; I believe that you're just misunderstanding how
the tags are supposed to work.  In particular, when you have a document
like this:

  <a>
   <b>foo</b>
  </a>

then an XPath expression like '/a/b' refers to the element <b>foo</b>,
which has a string value of 'foo'.  Thus,

  <x:out select="$doc/a/b" />

would in this case print 'foo'.  You have to consider why you're using
<x:out> if you really just want the full output of <x:transform>.  You
might instead wish to write simply:

 <x:transform xml="${xml}" xsl="${xsl}" />

and not buffer the output.

You might wish to reapproach the problem from first principles, reading
the JSTL specification and the XPath specification.  See

  http://java.sun.com/products/jstl

and

  http://www.w3.org/tr/xpath

Hope that helps.  By the way, in the future, it's a little easier for
people (or at least for me!) to help if you factor out the problem a
little more, reducing it to a base example and then including it inline.  
Sometimes, for particularly tricky problems, entire pages are useful, but
going through four pages takes a while, and it's not the most efficient
way to address a focused question.

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


JSTL XML x:transform and x:out work, but not together (was: x:transform and x:out fetch no data)

Posted by John Hicks <ja...@gulfbridge.net>.
Thanks to Shawn for clueing me in on the architecture of 
the x:transform and x:out tags. I've revised my test files 
and now x:out, with properly addressed select values, does 
indeed output actual data after a transform.

The only problem is: x:out doesn't output all the 
transformed output. It strips any tags generated by the 
transform and only outputs plain text.

Yet if I use a simple x:transform tag instead of x:out, the 
newly generated tags *are* there.

Take a look at the following three-column page: 

http://gulfbridge.com/java/xml2Target.jsp

(Here are the source files:
http://gulfbridge.com/tomcatSource/xml2Target.jsp
http://gulfbridge.com/tomcatSource/xml2Source.xml
http://gulfbridge.com/tomcatSource/xml2Xsl.xsl
)

Take a look at the third column first, since it is 
formatted correctly. (This column is generated by an 
x:transform tag alone.) Note that the <h3> tags for the 
headline and the <em> tags to italicize "online world" have 
been generated by the xslt transform. (In the original xml 
I used my own <heading> and <italics> tags.)

So column three is formatted correctly. The only problem is 
that it contains the content of my entire xml document. I 
want to be able to use the x:out tag to extract only part 
of the content.

Now, in columns one and two I am using x:out tags to select 
only one column of data from my transformed document. You 
can see that the selection works correctly, but my <h3> and 
<em> tags are missing.

So it appears x:out is properly addressing my transformed 
document, but is failing to extract all of the transformed 
data.

According to the JSTL specs, the only option for the x:out 
tag is "escapeXml," which causes the angle brackets of tags 
to be translated to character entity codes. I don't want to 
do that, but the fact that it can do that implies that 
x:out is capable of outputting tags. (Just to be sure that 
I've tried all my options, I've set escapeXml to false in 
column one and true in column two, but neither shows a sign 
of outputting a tag, escaped or not escaped.)

Thus my question: How do I display in my jsp page a 
selected part of a transformed xml document -- including 
any embedded tags?

(I would think this would be the typical usage of JSTL XML: 
to fill in the various parts of a template using a single 
xml document as a data source.)

I hope my problem is as before: that I'm just too blind or 
ignorant to see the obvious. If so, I apologize in advance 
and thank you for your patience and tolerance:)

--John Hicks


On Wednesday 25 September 2002 10:42 am, Shawn wrote:
> On Wed, 25 Sep 2002, John Hicks wrote:
> > Any ideas on why x:transform and x:out aren't working
> > in my case?
>
> Hi John.  I think you're just missing a general
> principle:  if you use <x:transform> to run an XSLT
> transformation, the output of the XSLT stylesheet is
> stored in the variable you indicate by 'var'.  Your tags,
> however, are trying to refer to the *input* document. 
> For instance, you write
>
>   <x:out select="$source/pageContent/column1" />
>
> This XPath express make sense for the xmlSource.xml file
> you're parsing, but it's not useful for the XSLT output,
> which looks like this:
>
>  <html>
>    ...
>  </html>
>
> Please let me know if you have any additional questions,
> and ensure that you're using <x:transform> correctly: 
> see the spec or the books that describe how it works in
> detail.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL XML x:transform and x:out fetch no data

Posted by Shawn Bayern <ba...@essentially.net>.
On Wed, 25 Sep 2002, John Hicks wrote:

> Any ideas on why x:transform and x:out aren't working in my case?

Hi John.  I think you're just missing a general principle:  if you use
<x:transform> to run an XSLT transformation, the output of the XSLT
stylesheet is stored in the variable you indicate by 'var'.  Your tags,
however, are trying to refer to the *input* document.  For instance, you
write

  <x:out select="$source/pageContent/column1" />

This XPath express make sense for the xmlSource.xml file you're parsing,
but it's not useful for the XSLT output, which looks like this:

 <html>
   ...
 </html>

Please let me know if you have any additional questions, and ensure that
you're using <x:transform> correctly:  see the spec or the books that
describe how it works in detail.

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: JSTL XML x:transform and x:out fetch no data

Posted by Shawn Bayern <ba...@essentially.net>.
On Wed, 25 Sep 2002, Ben Ramsey wrote:

> <c:import url="/xmlSource.xml" var="xml" />
> <c:import url="/xmlXsl.xsl" var="xsl" />
> <x:transform xml="${xml}" xslt="${xsl}" var="source" />
> 
> If I understand things correctly, then the transform performs the
> transformation and stores the output in the variable you have specified.
> However, you cannot access the content of the variable with x:out and XPath
> like you can an XML variable because it's not parsed as XML (but before you
> can access the contents of an XML variable with XPath, you would also have
> to x:parse it first).  Instead, you should just print out the output of the
> transformation with c:out.

No, what he did was fine on that count.  The <x:transform> tag exposes a
DOM and is designed to let its output be read with <x:out>, <x:if>, and
the other JSTL XML-manipulation tags.  The problem is just that his XPath
expression was inappropriate for the output that his specific
transformation produced.

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: JSTL XML x:transform and x:out fetch no data

Posted by Ben Ramsey <be...@eureka-interactive.com>.
<c:import url="/xmlSource.xml" var="xml" />
<c:import url="/xmlXsl.xsl" var="xsl" />
<x:transform xml="${xml}" xslt="${xsl}" var="source" />

If I understand things correctly, then the transform performs the
transformation and stores the output in the variable you have specified.
However, you cannot access the content of the variable with x:out and XPath
like you can an XML variable because it's not parsed as XML (but before you
can access the contents of an XML variable with XPath, you would also have
to x:parse it first).  Instead, you should just print out the output of the
transformation with c:out.

<c:out value="${source}"/>

Hope that helps.

-Ben Ramsey

Technical Director
EUREKA! INTERACTIVE, INC.

*  Phone: (770) 642-0390
*  Fax: (770) 216-1702
*  Web: www.eureka-interactive.com
*  E-mail: ben@eureka-interactive.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>