[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Getting unique nodes filtering by several attribut

Subject: RE: Getting unique nodes filtering by several attributes and mixing files
From: Jarno.Elovirta@xxxxxxxxx
Date: Tue, 25 Nov 2003 10:45:23 +0200
xsl unique nodes
Hi,

> One of the XML files (week_schedule.xml) is the list of 
> programs to be on
> air for
> two different TV channels. This list contains an "onAir" node for each
> advertisment
> (commercials) block. It's the only way to know which programs 
> will be on air
> next
> week, yes :(

…

> <!-- my_would_be_even_better_result.xml -->
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <tv>
>   <program progName='Friends' date='17/11/2003'
> 	channel='1' weekDay='Mon' start='10:00' end='10:45' 
> ads='10:15,10:30'/>
>   <program progName='Friends' date='23/11/2003'
> 	channel='1' weekDay='Sun' start='09:00' end='09:45' 
> ads='14:15,14:30,...'/>
>   <program progName='X-Files' date='22/11/2003'
> 	channel='2' weekDay='Sat' start='14:00' end='15:30' 
> ads='09:15,09:30'/>
> </tv>

  <xsl:variable name="sep" select="'&#xE000;'"/>
  <xsl:variable name="schedule" select="document('week_schedule.xml', /)"/>
  <xsl:key name="lookup" match="onAir" use="concat(@progName, $sep, @weekDay, $sep, @channel)"/>
  <xsl:template match="programs">
    <tv>
      <xsl:for-each select="program">
        <xsl:copy>
          <xsl:variable name="key" select="concat(@progName, $sep, @weekDay, $sep, @channel)"/>
          <xsl:for-each select="$schedule">
            <xsl:variable name="air" select="key('lookup', $key)"/>
            <xsl:copy-of select="$air/@date"/>
            <xsl:attribute name="adsAt">
              <xsl:for-each select="$air/@adsAt">
                <xsl:if test="not(position() = 1)">,</xsl:if>
                <xsl:value-of select="."/>
              </xsl:for-each>
            </xsl:attribute>
          </xsl:for-each>
          <xsl:copy-of select="@*"/>
        </xsl:copy>
      </xsl:for-each>
    </tv>
  </xsl:template>

Will you get you almost there, you just need to add sorting based on program name and airdate—you need to do a look up to get the date, but you can't use the key for that, sorry. See the FAQ on how to sort dates.

Cheers,

Jarno - Revolution By Night: Faithless (Edit) (by Ronan Harris)

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.