Welcome to WebmasterWorld Guest from 54.144.68.27

Forum Moderators: httpwebwitch

Message Too Old, No Replies

XML > XSL Help

Xml, Xsl, Xslt

     

smeg

6:08 pm on Jun 17, 2008 (gmt 0)

5+ Year Member



Hi, this is my first post here, and of course it is asking for help.
I am taking a class "Introduction to XML" and I have a couple of pracitice tasks for my exam, and I am stuck on this one. Can someone plesae solve it, and try to explain...
I still did not get my head around XSLT and XPath, so I am here trying to get some help.

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]

httpwebwitch

6:53 pm on Jun 17, 2008 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Hi smeg,
Just so I understand it, this problem has a few ingredients:

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

smeg

7:00 pm on Jun 17, 2008 (gmt 0)

5+ Year Member



Yes httpwebwitch it is just like U explained. But inputs do not need to be 2 and 4 only it can be any number.
I am sorry I have no code or smthg, but only thing I have is the task, like i wrote it...

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>

httpwebwitch

7:54 pm on Jun 18, 2008 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



hi smeg,
since this is a school exam, giving you a working, full solution would be unethical. It behooves you to learn the course material and come up with your own solution, especially since the solution contributes to your grade.

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!

 

Featured Threads

Hot Threads This Week

Hot Threads This Month