jstl if xsl problem

im not sure how to go about doing this:

<x:forEach select="$resume/ResumeAdditionalItems//ResumeAdditionalItem">

//i need to store the value of type but how?

// i then need to have a if statement to compare the last value, if its not a new type i want to place the

//description in the previous cell

like.....

|Type Name| Description |

|Technical| Java|

| | C#|

|Organisational | Teamwork|

<tr>

<td>

<x:out select ="@type" />

</td>

<td>

<x:out select="Description"/>

</td>

</tr>

</x:forEach>

[835 byte] By [h1400046a] at [2007-11-26 19:11:14]
# 1
What does the most relevant XML structure look like?
appy77a at 2007-7-9 21:08:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

<StructuredXMLResume>

<Resume>

<ResumeAdditionalItems>

- <Demographics>

- <PersonDescriptors>

- <BiologicalDescriptors>

<DateOfBirth>2005-08-02</DateOfBirth>

</BiologicalDescriptors>

</PersonDescriptors>

</Demographics>

- <ResumeAdditionalItem type="Technical">

<Description>Studied as part of degree, experience on placement</Description>

</ResumeAdditionalItem>

- <ResumeAdditionalItem type="Organisational">

<Description>1st year only</Description>

</ResumeAdditionalItem>

- <ResumeAdditionalItem type="Technical">

<Description>Learnt on placement</Description>

</ResumeAdditionalItem>

</ResumeAdditionalItems>

</StructuredXMLResume>

</Resume>

h1400046a at 2007-7-9 21:08:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

There's nothing wrong in implementing the solution inside the JSP, but I see a limitation with JSTL xml tags, when it comes to a bit more complex display of information.

Would you consider transforming it inside an XSLT instead?

XSLT is better equipped to handle complex XML operations in comparison to JSTL XML tags.

Then you could just output the result of the transformation inside JSP.

If you want to continue with transforming it inside the JSP itself, look for "XSLT 1.0 Group By" on Google, and you could use that XPath there. I don't know grouping yet.

Another option is to use XTags - another tag library - it is more powerful than JSTL XML tags but the only drawback is that XTags is not a standard / finalized release *yet*. So it won't be stable and there's not guarantee that it's features will continue to be developed as they stand now.

Message was edited by:

appy77

appy77a at 2007-7-9 21:08:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
it does appear that jstl doesnt offer the functionality i require, so therefore it seems that creating a xslt instead i more sensible, how do i pass the xslt back the jsp page?
h1400046a at 2007-7-9 21:08:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Very simple:

with JSTL 1.1

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>

<html>

<head><title>Transforming XML with XSLT inside a JSP</title></head>

<body>

<c:import url="/rootfolder/somefolder/somefile.xml" var="xml"/>

<c:import url="/rootfolder/somefolder/somefile.xsl" var="xsl"/>

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

</body>

</html>

appy77a at 2007-7-9 21:08:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

thanks

can you show me how to do the if in normal xslt?

<xsl:for-each select="Resume/StructuredXMLResume/EducationHistory">

<xsl:for-each select="Resume/StructuredXMLResume/Achievements">

<xsl:if "Resume/StructuredXMLResume/Achievements/Achievement/IssuingAuthority" =

</xsl:for-each>

</xsl:for-each>

h1400046a at 2007-7-9 21:08:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Why can't you just use <c:set> to save the current whatever it is you want to compare?
DrClapa at 2007-7-9 21:08:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
i would love to but i dont know how to set varables with the value of the x select statement?
h1400046a at 2007-7-9 21:08:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

You could do this:

<c:set var="someVar"><x:out select="SomeNode"/></c:set>

The above statement sets the value of SomeNode into someVar.

You can check with the XSLT mailing list if you want to transform it in XSLT:

http://www.mulberrytech.com/xsl/xsl-list/

I would have helped you with the XSLT part but I'm new to the concept of "grouping".

Message was edited by:

appy77

appy77a at 2007-7-9 21:08:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

why does this xslt not work. it compiles but its not finding any matches when i know they do exist

<xsl:for-each select="Resume/StructuredXMLResume/EducationHistory">

<xsl:variable name="school" select="SchoolOrInstitution/SchoolName"/>

<xsl:for-each select="Resume/StructuredXMLResume/Achievements">

<xsl:variable name="courseschool" select="Achievement/IssuingAuthority"/>

<xsl:if test="$school = $courseschool">

<xsl:value-of select='Achievement/Description'/>

</xsl:if>

</xsl:for-each>

</xsl:for-each>

h1400046a at 2007-7-9 21:08:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

[nobr]i tried what the jstl as well and its matching them all and printing them all to evey box which isnt right

<x:forEach select="$resume//EducationHistory">

<c:set var="school"><x:out select="SchoolOrInstitution/SchoolName"/></c:set>

<x:forEach select="$resume//Achievements">

<c:set var="courseschool"><x:out select="Achievement/IssuingAuthority"/></c:set>

<c:if test ="${school = courseschool}">

<x:out select="Achievement/Description"/>

<br>

</c:if>

</x:forEach>

</x:forEach>

[/nobr]

h1400046a at 2007-7-9 21:08:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12
In XSLT instead of using xsl:for-each , make use of xsl:template and match the node you wish to process.xsl:template is much more convenient than xsl:for-each in xslt. Also the for loop in XSLT is a bit different, one cannot break out of a for loop.
appy77a at 2007-7-9 21:08:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13
but if there is more than one how does it know to go to the next if i dont use a for each?
h1400046a at 2007-7-9 21:08:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 14
because that's how xsl:template works, it iterates over all the child nodes of a given node.
appy77a at 2007-7-9 21:08:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 15
the xslt doesnt compile using <xsl:template match="Resume/StructuredXMLResume/Achievements">
h1400046a at 2007-7-9 21:08:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 16
ok ive got the template match part working now but its now not itterating over each one, how can i get it to get the nexT?
h1400046a at 2007-7-9 21:08:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...