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 3rd, 2004, 10:44 AM
larsi larsi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 3 larsi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Xslt Dynamic columns with selection

Hi!

I need a selection of a file listed in three columns.

A good solution that almost cover what I need is is shown in this a previous topic
http://forums.devshed.com/t102219/s.html&highlight=xslt+columns
I can't figure out what todo when I need to make a selection on which items to show.

Example xml:
Code:
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<groups>
	<group name="myChannels">
		<channel name="ABC" type="TV" url="..." format="mpeg2"/>
		<channel name="BBB" type="TV" url="..." format="mpeg2"/>
		<channel name="CCCC" type="Radio" url="..." format="wma"/>
		<channel name="DDD" type="Radio" url="..." format="wma"/>
		<channel name="EEE" type="Radio" url="..." format="wma"/>
		<channel name="FFF" type="TV" url="..." format="mpeg2"/>
		<channel name="DDD" type="TV" url="..." format="mpeg2"/>
	</group>
</groups>


What I need is to display all TV channels (type=TV) in a list with 3 columns. Things works fine in example below when showing all channels.

Example xslt:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:param name="groupName">myChannels</xsl:param>
	<xsl:template match="/">
		<html>
			<body>
				<table align="center">
					<xsl:apply-templates select="groups/group[@name=$groupName]"/>
				</table>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="channel[position() mod 3 = 1]">
		<tr>
			<xsl:call-template name="inner">
				<xsl:with-param name="order" select="position()"/>
			</xsl:call-template>
		</tr>
	</xsl:template>
	<xsl:template name="inner">
		<xsl:param name="order"/>
		<xsl:for-each select=". | following-sibling::channel[position() <3]">
			<td width="250">
				<xsl:value-of select="$order + (position()-1)"/> : <xsl:value-of select="@name"/>
			</td>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>


But how do I select only the channels with type=TV? I've tried replacing the line:
Code:
<xsl:apply-templates select="groups/group[@name=$groupName]"/>

with this one
Code:
<xsl:apply-templates select="groups/group[@name=$groupName]/channel[@type='TV']"/>

and tried refering to the parent node, but I can't get it working.

I be really glad if someone could help!
Thanks alot!

Regards,

Larsi

Reply With Quote
  #2  
Old August 3rd, 2004, 11:12 AM
kid23 kid23 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 62 kid23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
if I'm not mistaken, this should be the answer:

<xsl:apply-templates select="groups/group[@name=$groupName and channel[@type='TV']]"/>

Reply With Quote
  #3  
Old August 4th, 2004, 02:47 AM
larsi larsi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 3 larsi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to select only TV and no Radio types?

Hi and thanks for the reply!

No change in behavior when I use your suggestion. When I type in 'TV' I get a list of all the entrires (including the Radio types). When I type in 'Radio' I get all the 'TV' types as well. If I type in a not listed type, no entries are selected.

This is the output from with your suggestion:
Code:
<table align="center">
			<tr>
				<td width="250">1 : ABC</td>
				<td width="250">2 : BBB</td>
				<td width="250">3 : CCCC</td>
			</tr>
			<tr>
				<td width="250">4 : DDD</td>
				<td width="250">5 : EEE</td>
				<td width="250">6 : FFF</td>
			</tr>
			<tr>
				<td width="250">7 : GGG</td>
			</tr>
		</table>

As you see it includes 'CCCC' 'DDD' and 'EEE' which is radio tags also.

Any ideas how to do this?

Reply With Quote
  #4  
Old August 4th, 2004, 08:41 AM
kid23 kid23 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 62 kid23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
I made only quick tests, but the xpath you had provided in your first post was right :

<xsl:apply-templates select="groups/group[@name=$groupName]/channel[@type='TV']"/>

With this selection, you only get the 'TV' channels. Your problem comes from how you want to arrange the data.

To see that this is well the problem, turn this line:

<xsl:template match="channel[position() mod 3 = 1]">

into this:

<xsl:template match="channel">

And the first column will display the right selection. Unfortunately, you'll still have data in the 2 other columns.

I don't know exactly how you can achieve what you're trying to do.. but if I find a solution, I'll let you know

It seems feasible though.

Reply With Quote
  #5  
Old August 4th, 2004, 11:22 AM
larsi larsi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 3 larsi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks again for the reply!

Yes, I've also tried several different approaches, but I can't figure out how to solve this.

I agree with you, this should be feasible. In first sight it seems like it should be a straightforward solution to this, but I can't find it

I appreciate any attempts to solve this.

Thanks alot

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Xslt Dynamic columns with selection


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


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





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