Displaying attributes of nodes with duplicate values in an XML file using XLST
Hi there,
Using XSLT - I'm looking to write code to display VideoPlusCodes, Slot date, and times from the XML below in order to show Slot date and time information from nodes where duplicate VideoPlusCodes exist. This is part of a project I'm having difficulty with getting started. I'd apreciate if anyone could help!
For example, from the following XML code snippet - I'd like to display:
12345
11/01/2010 BBC1 21:00
2/01/2010 BBC1 21:00
<Slot date='11/01/2010'>
<Channel name='BBC1' time='21:00' duration='30' rating='PG'>
<Breaks>
<!-- leave blank, used by shedulers -->
</Breaks>
</Channel>
<Title repeat='n' text='y' >News</Title>
<Description>Main News</Description>
<Category>
<Entry>News</Entry>
<SubEntry>Current Affairs</SubEntry>
</Category>
<ProgramSpecific>
</ProgramSpecific>
<VideoplusCode>12345</VideoplusCode>
<Comment>
May run late due to Soccer match
</Comment>
</Slot>
<Slot date='2/01/2010'>
<Channel name='BBC1' time='21:00' duration='30' rating='PG'>
<Breaks>
<!-- leave blank, used by shedulers -->
</Breaks>
</Channel>
<Title repeat='n' text='y' >News</Title>
<Description>Main News</Description>
<Category>
<Entry>News</Entry>
<SubEntry>Current Affairs</SubEntry>
</Category>
<ProgramSpecific>
</ProgramSpecific>
<VideoplusCode>12345</VideoplusCode>
<Comment>
</Comment>
</Slot>
Regards,
Dave.
/Slot[VideoplusCode = <xsl:value-of select=".">]
hi
I didn't tried this out but you may you could run through all <VideoplusCode> and inside the template you use this xpath expression:
Code:
/Slot[VideoplusCode = <xsl:value-of select=".">]
now you should get all the <slot>s with the same VideoplusCode entry.
I've never tried this, I dont know if it's possible to use xslt inside xpath, but maybe it works.
Sorry for my weird englisch. It's already late. But I think you know what I meant.
Unfortunately that does not work, but thanks for trying anyway! It would be nice if it did!
this works:
Code:
<xsl:template match="/">
<xsl:apply-templates select="//VideoplusCode" />
</xsl:template>
<xsl:template match="VideoplusCode">
<xsl:if test="position() = 1">
<xsl:apply-templates select="//Slot[VideoplusCode = node() ]/@date"/>
</xsl:if>
</xsl:template>
<xsl:template match="@date">
<xsl:value-of select="."/>
</xsl:template>
Thanks for your continued support here but this seems to be only displaying dates..? Like this..
11/01/2010
11/01/2010
2/01/2010
11/01/2010
11/01/2010
11/01/2010
2/01/2010
11/01/2010
11/01/2010
2/01/2010
11/01/2010
2/01/2010
11/01/2010
2/01/2010
11/01/2010
11/01/2010
2/01/2010
2/01/2010
2/01/2010
yes I know you need to add the other templates for your output and adjust the xpath expression
Thank you
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks