Forum Moderators: open
So the task:
Using the extended/expanded? XML file cdkatalog (or some other .xml file as long as it has a couple of entrys inside), create an XSL file which will display the information from the xml file as follows: first page should display a logo followed by an assigned number of lines; second and all subsequent pages should display a logo and an assigned number of lines. The number of lines on the first page and other pages is defined via an input form, eg:
Number of lines on page 1:
Number of lines on other pages:
So, sorry for my english, I am from Croatia, and i translated it as best I coudl!
[edited by: httpwebwitch at 6:43 pm (utc) on June 17, 2008]
[edit reason] No example links, please [/edit]
1) a <form> with two inputs:
<label>Number of lines on page 1:</label> <input value="2"/>
<label>Number of lines on other pages:</label> <input value="4"/>
2) an XML file
3) an XSLT file which produces output that resembles this:
LOGO (showing 2 items)
-item
-item
LOGO (showing 4 items)
-item
-item
-item
-item
LOGO (showing 4 items)
-item
-item
-item
-item
LOGO (showing 4 items)
-item
-item
-item
-item
XML has a lot of entries about 70. I just copy/paste a part of the code.
XML code goes like this:
<?xml version="1.0" encoding="UTF-8"?>
<katalog>
<cd>
<naslov>Empire Burlesque</naslov>
<izvodac>Bob Dylan</izvodac>
<drzava>USA</drzava>
<distributer>Columbia</distributer>
<cijena>10.90</cijena>
<godina>1985</godina>
</cd>
<cd>
<naslov>Hide your heart</naslov>
<izvodac>Bonnie Tyler</izvodac>
<drzava>UK</drzava>
<distributer>CBS Records</distributer>
<cijena>9.90</cijena>
<godina>1988</godina>
</cd>
<cd>
<naslov>Greatest Hits</naslov>
<izvodac>Dolly Parton</izvodac>
<drzava>USA</drzava>
<distributer>RCA</distributer>
<cijena>9.90</cijena>
<godina>1982</godina>
</cd>
<cd>
<naslov>Still got the blues</naslov>
<izvodac>Gary Moore</izvodac>
<drzava>UK</drzava>
<distributer>Virgin records</distributer>
<cijena>10.20</cijena>
<godina>1990</godina>
</cd>
</katalog>
I'll give you this, which is deliberately incomplete but should be enough to point you in the right direction.
Note that the two variables first and other have been defined at the top of the stylesheet, and they are used along with position() and the modulus operator to put page breaks in the right positions. Given this example, it's up to you to figure out why it works, and how to apply the technique to your practice problem.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes" /><xsl:variable name="first">3</xsl:variable>
<xsl:variable name="other">5</xsl:variable>
<xsl:template match="katalog">
<hr/>LOGO
<xsl:apply-templates select="cd"></xsl:apply-templates>
</xsl:template><xsl:template match="cd">
<xsl:if test="((position()-($first+1)) mod $other) = 0">
<hr/>LOGO
</xsl:if>
<br/> <xsl:value-of select="godina"/>
</xsl:template></xsl:stylesheet>
Good luck!