jstl xsl problem

[nobr]i have a xml structure that is designed according to the hr-xml standard

the xml file has a number of education historys - schools/organisations

and a number of achievements - courses

from the code below the education is selected fine, but i want to select the achivements whoch have been done at the specific school/organisation, but i dont know how to compare the schools

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

<tr>

<td>

<x:out select="SchoolOrInstitution/SchoolName"/>

<dl>

<dt>

Address:

<dd>

<br>

<x:out select="SchoolOrInstitution/PostalAddress/DeliveryAddress/BuildingNumber"/>

<br>

<x:out select="SchoolOrInstitution/PostalAddress/DeliveryAddress/StreetName"/>

<br>

<x:out select="SchoolOrInstitution/PostalAddress/Region"/>

<br>

<x:out select="SchoolOrInstitution/PostalAddress/Municipality"/>

<br>

<x:out select="SchoolOrInstitution/PostalAddress/PostalCode"/>

</dd>

</dt>

</dl>

</td>

<td>

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

<x:if select Achievement/IssuingAuthority =

</td>

<td>

</td>

<td>

<x:out select="SchoolOrInstitution/Degree/DatesOfAttendance/StartDate/AnyDate"/> -

<x:out select="SchoolOrInstitution/Degree/DatesOfAttendance/EndDate/AnyDate"/>

</td>

</tr>

</x:forEach>

the achievements xml looks like this:

- <Achievements>

- <Achievement>

<Description>English C</Description>

<IssuingAuthority>Grammer School</IssuingAuthority>

</Achievement>

</Achievements>

education xml looks like this:

<EducationHistory>

- <SchoolOrInstitution>

<SchoolName>Grammer School</SchoolName>

- <Degree>

- <DatesOfAttendance>

- <StartDate>

<AnyDate>2020-06-04</AnyDate>

</StartDate>

- <EndDate>

<AnyDate>2023-08-04</AnyDate>

</EndDate>

</DatesOfAttendance>

</Degree>

- <PostalAddress>

<PostalCode>Uk1903</PostalCode>

<Region>Town</Region>

<Municipality>County</Municipality>

- <DeliveryAddress>

<StreetName>Road</StreetName>

<BuildingNumber>12</BuildingNumber>

</DeliveryAddress>

</PostalAddress>

</SchoolOrInstitution>

</EducationHistory>

[/nobr]

[3145 byte] By [h1400046a] at [2007-11-26 18:36:56]
# 1

According to the documentation, the x:forEach tag "Evaluates the given XPath expression and repeats its nested body content over the

result, setting the context node to each element in the iteration."

This means that while you're in the one forEach loop, the context is set to the current record. You're using that to good effect with the <x:out> tags.

Now you want to iterate through an unrelated xml file? Or is it part of the same one? You're trying to access it via $resume, which is confusing me a little.

A nested forEach loop even on a completely different xml file is still assuming the context of the parent loop. Which is probably causing you a problem.

Hope this explanation helps some,

evnafets

evnafetsa at 2007-7-9 6:10:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
its all part of the same file? how would you compare the two?
h1400046a at 2007-7-9 6:10:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

[nobr]i tried this but it just brings back all the records.. the if cant be right, any ideas?

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

<x:if select = "Achievement/IssuingAuthority[$resume/EducationHistory/SchoolOrInstitution/SchoolName]">

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

<br>

</x:if>

</x:forEach>

[/nobr]

h1400046a at 2007-7-9 6:10:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

this doesnt work eaither

<x:if select = "Achievement[IssuingAuthority = $resume/EducationHistory/SchoolOrInstitution/SchoolName]">

nor this

<x:if select = "Achievement[IssuingAuthority = '$resume/EducationHistory/SchoolOrInstitution/SchoolName']">

h1400046a at 2007-7-9 6:10:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
hi this is still baffling me?
h1400046a at 2007-7-9 6:10:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

[nobr]> According to the documentation, the x:forEach tag

> "Evaluates the given XPath expression and repeats its

> nested body content over the

> result, setting the context node to each element

> in the iteration."

>

> This means that while you're in the one forEach loop,

> the context is set to the current record. You're

> using that to good effect with the <x:out> tags.

Evnafets,

I thought the same too that if an x:forEach is nested inside another x:forEach and if each x:forEach is iterating over XML files stored in a two separate XML source files.

But the Jakarta Taglibs group members claim that it is supposed to work according to this bug report here:

http://issues.apache.org/bugzilla/show_bug.cgi?id=41481

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Anyway, if you are unable to make it work inside the JSP , try to do the exact same transformation in an XSLT file and then call

<x:transform inside the JSP

Here's a nice article on how to merget 2 XML files into one:

http://www.xml.com/pub/a/2002/03/06/xslt.html , if you want to take that appropach.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I tried a simpler example of your case with the following code and as I expected , the inner loop did not work, only the outer one worked.

--

books.xml

--

><?xml version="1.0" encoding="UTF-8"?>

<books>

<book>

<isbn>3232334</isbn>

<title>ABC</title>

<author_id>1</author_id>

</book>

<book>

<isbn>9983434</isbn>

<title>XYZ</title>

<author_id>2</author_id>

</book>

</books>

--

authors.xml

--

<?xml version="1.0" encoding="UTF-8"?>

<authors>

<author>

<id>1</id>

<name>James</name>

</author>

<author>

<id>2</id>

<name>Kelly</name>

</author>

</authors>

index.jsp

<%@ 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></title></head>

<body>

<c:import url="books.xml" var="books_xml"/>

<c:import url="authors.xml" var="authors_xml"/>

<x:parse var="parsedBooks" doc="${books_xml}"/>

<x:parse var="parsedAuthors" doc="${authors_xml}"/>

<x:forEach select="$parsedBooks/books/book">

<x:out select="isbn"/><br/>

<x:forEach select="$parsedAuthors/authors/author">

<x:out select="id"/>

</x:forEach>

</x:forEach>

</body>

</html>

In the above sample only the isbn was printing , but the author id from the 2nd XML file wasn't printing at all.[/nobr]

appy77a at 2007-7-9 6:10:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...