homepage Welcome to WebmasterWorld Guest from 54.204.249.184
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
XML > XSL Help
Xml, Xsl, Xslt
smeg




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

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




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

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




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

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




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

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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved