Click to See Complete Forum and Search --> : Displaying attributes of nodes with duplicate values in an XML file using XLST


daveomcgee
11-29-2009, 01:49 PM
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.

Specht08
11-29-2009, 04:15 PM
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:

/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.

Specht08
11-29-2009, 04:18 PM
Sorry for my weird englisch. It's already late. But I think you know what I meant.

daveomcgee
11-29-2009, 05:15 PM
Unfortunately that does not work, but thanks for trying anyway! It would be nice if it did!

Specht08
11-29-2009, 05:34 PM
this works:

<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>

daveomcgee
11-29-2009, 06:16 PM
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

Specht08
11-29-2009, 06:54 PM
yes I know you need to add the other templates for your output and adjust the xpath expression

daveomcgee
11-29-2009, 07:09 PM
Thank you :)