Hello, some problems with XSL-FO

Hello All, I hope somebody can help me :)

Let me explain the project, I have two xml files (courses_codes.xml and courses.xml)
, I need to read this files and converted them to XSL-FO. The goal is to produce
a PDF file that contains course catalog information for a particular course
group (e.g. AFAM, CSCI, BIOL, etc.) for the 2003-2004 academic year. Also the
XSLT should accept a parameter named "group" that will determine which course group
information will be used (e.g. values for group might be "CSCI", "BIOL", "CHEM", etc).
The XSLT should also accept a parameter named "year".

The XLS-FO first creates a title, using the fullname of the course group selected,
them creates a Table of Contect (TOC) with all the courses, and those courses are
linked to an individual page containing the course information.

The courses in a group has to be unique, and the ones selected using the
global parameters (group, year)

So my questions is how can achive this ??


My XML files are :

courses_codes.xml

<courses_codes>
<course_groups>
<course_group code="AFAM" name="African American Studies"/>
<course_group code="ANTH" name="Anthropology and Archaeology"/>
</course_groups>
</courses_codes>

courses.xml

<dce_courses>
<course acad_year="2003" term_id="2" crn="21135">
<course_group>AFAM</course_group>
<course_num>E-110</course_num>
<title>Images of Africana People in Cinema</title>
<meeting>
<meeting_days>W</meeting_days>
<meeting_begin>1730</meeting_begin>
<meeting_end>1930</meeting_end>
<location>Sever Hall 110</location>
</meeting>
<course_head>
<person>
<person_name>Pashington Obeng</person_name>
<person_title>PhD, Visiting Lecturer on World Religions, Harvard Divinity School and Assistant Profess$
</person>
</course_head>
<description>An examination of the sociocultural, political, and economic aspects of Africana people throu$
</course>
<course acad_year="2003" term_id="2" crn="22066">
<course_group>ANTH</course_group>
<course_num>E-135</course_num>
<title>The Archaeology of the American Southwest</title>
<meeting>
<meeting_days>M</meeting_days>
<meeting_begin>1730</meeting_begin>
<meeting_end>1930</meeting_end>
<location>Harvard Hall 201</location>
</meeting>
<course_head>
<person>
<person_name>Steven A. LeBlanc</person_name>
<person_title>PhD, Senior Lecturer on Anthropology, Harvard University</person_title>
</person>
</course_head>
<description>This course considers the prehistory of the American Southwest from PaleoIndian times to Euro$
</course>
<dce_courses>

Thx for the help!!
Merry X-MAS!!

LuisM
[3394 byte] By [SRF] at [2007-11-18 15:03:05]
# 1 Re: Hello, some problems with XSL-FO
How much do you know about doing something like this ?

Start by getting xerces and xalan for java from http://xml.apache.org
With this xsl commandline utility (http://xml.apache.org/xalan-j/commandline.html) you can set name value parameter pairs. Which must of course be matched by <xsl:param name="paramname"/> elements in tthe xsl stylesheet.

Then write xml to formatting objects stylesheet.

Finally you need to find a formatting objects to pdf converter (I know there is a java implementation somewhere).
khp at 2007-11-10 3:28:28 >
# 2 Re: Hello, some problems with XSL-FO
I know XSLT, well I'm currently learning :)
I have xalan and coccon running. I'm using cocoon to output to
pdf format using pipeline.

I'm creating the TOC and the courses information, but I believe I'm doing it wrong, because is not working as it should...

This is my stylesheet (partial code :):

<?xml version="1.0" encoding="utf-8"?>
<!-- XSLT to Produce XSL-FO document -->
<!-- Need to accept a parameter named "year" -->
<!-- Need to accept a parameter named "group" -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
<xsl:output method="xml"/>

<!-- Our parameters -->
<xsl:param name="group" />
<xsl:param name="year" />

<!-- Create TOC -->
<fo:block>
<xsl:for-each select="//course[course_group=$group]">
<xsl:sort select="title" />
<fo:block text-align-last="justify">
<fo:basic-link>
<xsl:attribute name="internal-destination">
<xsl:value-of select="generate-id()" />
</xsl:attribute>
<xsl:value-of select="title"/>
<fo:leader leader-pattern="dots" />
<fo:page-number-citation>
<xsl:attribute name="ref-id">
<xsl:value-of select="generate-id()" />
</xsl:attribute>
</fo:page-number-citation>
</fo:basic-link>
</fo:block>
</xsl:for-each>
</fo:block>

The TOC works more a less :)
The problem comes when creating each course information, this is
what i'm doing:

<!-- Create Pages -->
<xsl:for-each select="//course[course_group=$group]">
<xsl:sort select="title" />
<fo:block break-before="page" xsl:use-attribute-sets="pdf-title">
<xsl:attribute name="id">
<xsl:value-of select="generate-id()" />
</xsl:attribute>
</fo:block>
<fo:block xsl:use-attribute-sets="page-title">
<xsl:value-of select="title" />,
<xsl:value-of select="course_num" />
(CRN:<xsl:value-of select="@crn" />)
</fo:block>
<fo:block xsl:use-attribute-sets="normal">
Meeting Information:
<fo:block>
Days: <xsl:value-of select="./metting/meeting_days" />
</fo:block>
<fo:block>
Begin: <xsl:value-of select="/metting/meeting_begin" />
</fo:block>
<fo:block>
End: <xsl:value-of select="/metting/meeting_end" />
</fo:block>
<fo:block>
Location: <xsl:value-of select="/metting/location" />
</fo:block>
<fo:block>
Professor: <xsl:value-of select="person_name" />
</fo:block>
<fo:block>
Title: <xsl:value-of select="person_name" />
</fo:block>
<fo:block>
Course Description: <xsl:value-of select="description" />
</fo:block>
</fo:block>
</xsl:for-each>

How can I select those course using the group and year parameters, have to be unique!!

Comments :)

thx a lot!!!!
Happy X-MAS!!

LuisMM
SRF at 2007-11-10 3:29:31 >
# 3 Re: Hello, some problems with XSL-FO
I know XSLT, well I'm currently learning :)
I have xalan and coccon running. I'm using cocoon to output to
pdf format using pipeline.

I'm creating the TOC and the courses information, but I believe I'm doing it wrong, because is not working as it should...

This is my stylesheet (partial code :):

<?xml version="1.0" encoding="utf-8"?>
<!-- XSLT to Produce XSL-FO document -->
<!-- Need to accept a parameter named "year" -->
<!-- Need to accept a parameter named "group" -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
<xsl:output method="xml"/>

<!-- Our parameters -->
<xsl:param name="group" />
<xsl:param name="year" />

<!-- Create TOC -->
<fo:block>
<xsl:for-each select="//course[course_group=$group]">
<xsl:sort select="title" />
<fo:block text-align-last="justify">
<fo:basic-link>
<xsl:attribute name="internal-destination">
<xsl:value-of select="generate-id()" />
</xsl:attribute>
<xsl:value-of select="title"/>
<fo:leader leader-pattern="dots" />
<fo:page-number-citation>
<xsl:attribute name="ref-id">
<xsl:value-of select="generate-id()" />
</xsl:attribute>
</fo:page-number-citation>
</fo:basic-link>
</fo:block>
</xsl:for-each>
</fo:block>

The TOC works more a less :)
The problem comes when creating each course information, this is
what i'm doing:

<!-- Create Pages -->
<xsl:for-each select="//course[course_group=$group]">
<xsl:sort select="title" />
<fo:block break-before="page" xsl:use-attribute-sets="pdf-title">
<xsl:attribute name="id">
<xsl:value-of select="generate-id()" />
</xsl:attribute>
</fo:block>
<fo:block xsl:use-attribute-sets="page-title">
<xsl:value-of select="title" />,
<xsl:value-of select="course_num" />
(CRN:<xsl:value-of select="@crn" />)
</fo:block>
<fo:block xsl:use-attribute-sets="normal">
Meeting Information:
<fo:block>
Days: <xsl:value-of select="./metting/meeting_days" />
</fo:block>
<fo:block>
Begin: <xsl:value-of select="/metting/meeting_begin" />
</fo:block>
<fo:block>
End: <xsl:value-of select="/metting/meeting_end" />
</fo:block>
<fo:block>
Location: <xsl:value-of select="/metting/location" />
</fo:block>
<fo:block>
Professor: <xsl:value-of select="person_name" />
</fo:block>
<fo:block>
Title: <xsl:value-of select="person_name" />
</fo:block>
<fo:block>
Course Description: <xsl:value-of select="description" />
</fo:block>
</fo:block>
</xsl:for-each>

How can I select those course using the group and year parameters, have to be unique!!

Comments :)

thx a lot!!!!
Happy X-MAS!!

LuisMM
SRF at 2007-11-10 3:30:29 >
# 4 Re: Hello, some problems with XSL-FO
I know XSLT, well I'm currently learning :)
I have xalan and coccon running. I'm using cocoon to output to
pdf format using pipeline.

I'm creating the TOC and the courses information, but I believe I'm doing it wrong, because is not working as it should...

This is my stylesheet (partial code :):

<?xml version="1.0" encoding="utf-8"?>
<!-- XSLT to Produce XSL-FO document -->
<!-- Need to accept a parameter named "year" -->
<!-- Need to accept a parameter named "group" -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
<xsl:output method="xml"/>

<!-- Our parameters -->
<xsl:param name="group" />
<xsl:param name="year" />

<!-- Create TOC -->
<fo:block>
<xsl:for-each select="//course[course_group=$group]">
<xsl:sort select="title" />
<fo:block text-align-last="justify">
<fo:basic-link>
<xsl:attribute name="internal-destination">
<xsl:value-of select="generate-id()" />
</xsl:attribute>
<xsl:value-of select="title"/>
<fo:leader leader-pattern="dots" />
<fo:page-number-citation>
<xsl:attribute name="ref-id">
<xsl:value-of select="generate-id()" />
</xsl:attribute>
</fo:page-number-citation>
</fo:basic-link>
</fo:block>
</xsl:for-each>
</fo:block>

The TOC works more a less :)
The problem comes when creating each course information, this is
what i'm doing:

<!-- Create Pages -->
<xsl:for-each select="//course[course_group=$group]">
<xsl:sort select="title" />
<fo:block break-before="page" xsl:use-attribute-sets="pdf-title">
<xsl:attribute name="id">
<xsl:value-of select="generate-id()" />
</xsl:attribute>
</fo:block>
<fo:block xsl:use-attribute-sets="page-title">
<xsl:value-of select="title" />,
<xsl:value-of select="course_num" />
(CRN:<xsl:value-of select="@crn" />)
</fo:block>
<fo:block xsl:use-attribute-sets="normal">
Meeting Information:
<fo:block>
Days: <xsl:value-of select="./metting/meeting_days" />
</fo:block>
<fo:block>
Begin: <xsl:value-of select="/metting/meeting_begin" />
</fo:block>
<fo:block>
End: <xsl:value-of select="/metting/meeting_end" />
</fo:block>
<fo:block>
Location: <xsl:value-of select="/metting/location" />
</fo:block>
<fo:block>
Professor: <xsl:value-of select="person_name" />
</fo:block>
<fo:block>
Title: <xsl:value-of select="person_name" />
</fo:block>
<fo:block>
Course Description: <xsl:value-of select="description" />
</fo:block>
</fo:block>
</xsl:for-each>

How can I select those course using the group and year parameters, have to be unique!!

Comments :)

thx a lot!!!!
Happy X-MAS!!

LuisMM
SRF at 2007-11-10 3:31:29 >
# 5 Re: Hello, some problems with XSL-FO
WOW quite a lot you were'nt telling. Your initial message gave the impression that you were starting from scratch. When you post crap like that, I have start from scratch, as it turns out this was an utter waste of my time. And I really really hate that. :mad:

If you want people to help you please be up front about what you have done so far. If you want help with your code, please post your entire code, looking at a few fragments out of context is very difficult. It's much easier to help you, if I can reproduce what you are doing.

How can I select those course using the group and year parameters
//course[course_group=$group and @acad_year=$year]
This should use the year and group parameters, to select the course.
khp at 2007-11-10 3:32:28 >
# 6 Re: Hello, some problems with XSL-FO
Sorry, about that wasting time, it was not my intention :)

What I need is to select those courses that math the global parameter year and group but have to be unique using the group parameter. This is what I have done so far, but is not working!

<?xml version="1.0" encoding="utf-8"?>
<!-- XSLT to Produce XSL-FO document -->
<!-- Need to accept a parameter named "year" -->
<!-- Need to accept a parameter named "group" -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
<xsl:output method="xml"/>

<!-- Our parameters -->
<xsl:param name="group" />
<xsl:param name="year" />

<!-- Keys -->
<xsl:key name="groups" match="course" use="course_group" />

<!-- Create TOC -->
<fo:block>
<xsl:for-each select="//course[@acad_year=$year][generate-id(.) = generate-id(key('groups', $group)[1])]">
<xsl:sort select="title" />
<fo:block text-align-last="justify">
<fo:basic-link>
<xsl:attribute name="internal-destination">
<xsl:value-of select="generate-id()" />
</xsl:attribute>
<xsl:value-of select="title"/>
<fo:leader leader-pattern="dots" />
<fo:page-number-citation>
<xsl:attribute name="ref-id">
<xsl:value-of select="generate-id()" />
</xsl:attribute>
</fo:page-number-citation>
</fo:basic-link>
</fo:block>
</xsl:for-each>
</fo:block>

I have create a ket for the groups, then in the TOC i want those elements that match group and year and are unique to group.

Any comments ?

Thx a lot

LuisMM
SRF at 2007-11-10 3:33:27 >
# 7 Re: Hello, some problems with XSL-FO
Lets take a close look at the expression //course[@acad_year=$year][generate-id(.) = generate-id(key('groups', $group)[1])]

//course[@acad_year=$year]

selects the node set where @acad_year=$year this is fine.

However

key('groups', $group)[1]

Selects the first element, among all the course elements, where $group matches course_group. So unless the @acad_year attribute of this element, matches your $year parameter. You will get an empty result.

All in all I don't quite see what you are hoping to gain by using the key and generate-id functions.
The group value is in itself not enough to uniquely identify an element, and simply picking the first one at random, and then expect it to match your $year parameter obviously won't work.

Calling generate-id on a random element dosn't make an element more or less unique, it just generates a value that uniquely identifies your randomly chosen element.
khp at 2007-11-10 3:34:33 >