|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
if I'm not mistaken, this should be the answer:
<xsl:apply-templates select="groups/group[@name=$groupName and channel[@type='TV']]"/> |
|
#3
|
|||
|
|||
|
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? |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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 ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Xslt Dynamic columns with selection |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|