XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 16th, 2004, 11:27 AM
Ru_ Ru_ is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 2 Ru_ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
newbie: XSL question.

Hi board,

If any of y'all w/ the know how on this can respond I'd be grateful.

Ok my question is this.. I'm only playing around with XML and XSL primarily for XSLT transformations on a large publishing industry site.

So I have my XML file, a dump of for example a bunch of Sport stories from a newspaper (very short listing):

PHP Code:
<category_listing name="Sport">
<
category name="Soccer">
<
story>
<
rank>1</rank>
<
byline>Author here X</byline>
<
headline>Big name transfer to UK Club</headline>
<
summary>Soccer story summary here</summary>
</
story>
<
story>
<
rank>2</rank>
<
byline>Author here X</byline>
<
headline>The second ranked story</headline>
<
summary>Soccer story summary here</summary>
</
story>
<
story>
<
rank>3</rank>
<
byline>Author here X</byline>
<
headline>The third ranked story</headline>
<
summary>Soccer story summary here</summary>
</
story>
</
category>
<
category name="Baseball">
<
story>
<
rank>1</rank>
<
byline>Author here X</byline>
<
headline>Baseball legend does something</headline>
<
summary>Baseballstory summary here</summary>
</
story>
<
story>
<
rank>2</rank>
<
byline>Author here X</byline>
<
headline>The second ranked story</headline>
<
summary>Baseball story summary here</summary>
</
story>
<
story>
<
rank>3</rank>
<
byline>Author here X</byline>
<
headline>The third ranked story</headline>
<
summary>Baseball story summary here</summary>
</
story>
</
category>
</
category_listing


Ok so that's a brief example of the XML.

So using XSL I can successfully transform this into well formatted html with category names in bold followed by the ranked stories etc.

I can also take for example a rank='1' story and display it anywhere. However, this is where I'm stuck and unsure as to whether this is possible with XSL.

Can I use XSL to extract (dont take me literally) the rank=1 stories and display them before the other categories as 'Top Stories' (which I have done) but then when my XSL works on outputting the individual Categories it omits headlines that appeared in the 'Top Stories' ie html would be like this.

TOP STORIES
- Big name transfer to UK Club
- Baseball legend does something

SOCCER
- The second ranked story
- The third ranked story

BASEBALL
- The second ranked story
- The third ranked story

Also, can I apply any sort of 'counter' to this process whereby I would only use 4 rank 1 stories and then for the rest rank 1's appear under their associated category... ?

Ok so hopefully you get what I'm trying to do. I don't expect you to write my code but if anyone can indicate if this is possible and indicate how I might do it that would be great.

Cheers
R


Reply With Quote
  #2  
Old August 16th, 2004, 11:46 AM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 6
This is definitely feasible. Basically you want a conditional statement, if rank=1 then... else...

Check out this tutorial:

http://www.w3schools.com/xsl/xsl_choose.asp
__________________
Hello, old friend...

Reply With Quote
  #3  
Old August 16th, 2004, 11:53 AM
Ru_ Ru_ is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 2 Ru_ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by khwang
This is definitely feasible. Basically you want a conditional statement, if rank=1 then... else...

Check out this tutorial:

http://www.w3schools.com/xsl/xsl_choose.asp


Thanks khwang,

Yes I'm familiar with the choose and have used it in this sucessfully to get those story[rank='1'] which I want.

However, for example if Sport has 8 categories I will only want to take four rank 1 stories for my 'Top Stories' section in the HTML.

Also if the rank 1 story appeared in Top Stories I do not want to duplicate it under its individual category listing as in the html output ex. above....?

Reply With Quote
  #4  
Old August 16th, 2004, 03:22 PM
NotGoddess's Avatar
NotGoddess NotGoddess is offline
Kung-fu Kitty
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 350 NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 9 m 2 sec
Reputation Power: 10
Send a message via AIM to NotGoddess
Quote:
Originally Posted by Ru_
Sport has 8 categories I will only want to take four rank 1 stories for my 'Top Stories' section in the HTML.

You can use a selective position() trick for this:
PHP Code:
<xsl:template name="showTopStories" match="/">
<
xsl:param name="count" />

<
xsl:for-each select="//story[rank=1]">
   <
xsl:if test="(position() <= $count)">
      <
p style="text-weight:bold;color:green"><xsl:value-of select="headline" /></p>
   </
xsl:if>
</
xsl:for-each>

</
xsl:template>

<
xsl:template match="/">

   <
xsl:call-template name="showTopStories">
      <
xsl:with-param name="count">4</xsl:with-param>
   </
xsl:call-template>

[...print 
other stories ]
</
xsl:template


Quote:
Originally Posted by Ru_
Also if the rank 1 story appeared in Top Stories I do not want to duplicate it under its individual category listing as in the html output ex. above....?

This I could not work out cleanly, but you might want to look into using call-template and with-param, doing a recursive call to increment the param.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > newbie: XSL question.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT