Search

Hi All

I appreciate any help with this issue. I know it is related to Data Source Chaining but not matter how much I read about it I just couldn't wrap my head around the concept.

I want to display a list of "Locations" in an RSS feed. I have the feed setup already.

Each Location belongs to an Area, which belongs to a City, which belongs to a Region, which belongs to a Country.

So I have 5 sections set up with Select Box Links which look like this:

Countries.country (name of the country)

Regions.country (SBL to Countries.country)
Regions.region (name of the region)

Cities.region (SBL to Regions.region)
Cities.city (name of the city)

Areas.city (SBL to Cities.city)
Areas.area (name of the area)

Location.area (SBL to Areas.area)
Location.title (name of the location)

Here is what my XML looks like now to display all Locations. My data source "RSS Locations" uses the Location section as a source.

<xsl:template match="data">
    <xsl:for-each select="rss-locations/entry">
        <item>
            <title><xsl:value-of select="title"/></title>
            <area><xsl:value-of select="area"/></area>
        </item>
    </xsl:for-each>
</xsl:template>

How can I also add the City, Region, and Country of each location to this output?

As a first step, I tried creating a new Data Source called "RSS Areas" which uses the section "Areas" as a source, but couldn't figure out how the filtering works or the syntax to use it in my output.

Appreciate your help in advance.

Settings for RSS Locations data source:

  • in Output parameters select $ds-rss-locations.area (needed to filter next chained data source)
  • in Included elements select anything you wish and area (needed to cross-match in XSLT)

Chained data source for Areas:

  • set Name to Areas by ID
  • set Section to Areas
  • set a filter on System ID with value -1, {$ds-rss-locations.area}. This is what makes the chain. You filter this DS based on another DS value.
  • uncheck the Paginate results ... checkbox (not needed)
  • in Output parameters select $ds-areas-by-id.city (needed to filter next chained data source)
  • in Included Elements, select select anything you wish and city (needed to cross-match in XSLT)

Chained data source for Cities:

  • set Name to Cities by ID
  • set Section to Cities
  • set a filter on System ID with value -1, {$ds-areas-by-id.city}. This is what makes the chain. You filter this DS based on another DS value.
  • uncheck the Paginate results ... checkbox (not needed)
  • in Output parameters select $ds-cities-by-id.region (needed to filter next chained data source)
  • in Included Elements, select select anything you wish and region (needed to cross-match in XSLT)

... and apply the same process to Regions by ID and Countries by ID data sources.

Here's a demo XSLT:

<xsl:variable name="countries" select="/data/countries-by-id/entry"/>
<xsl:variable name="regions" select="/data/regions-by-id/entry"/>
<xsl:variable name="cities" select="/data/cities-by-id/entry"/>
<xsl:variable name="areas" select="/data/areas-by-id/entry"/>

<xsl:for-each select="/data/rss-locations/entry">
    <xsl:variable name="location" select="."/>
    <xsl:variable name="area" select="$areas[ @id = $location/area/item/@id ]"/>
    <xsl:variable name="city" select="$cities[ @id = $area/city/item/@id ]"/>
    <xsl:variable name="region" select="$regions[ @id = $city/region/item/@id ]"/>
    <xsl:variable name="country" select="$countries[ @id = $region/country/item/@id ]"/>

    <dl>
            <dt>Country</dt>
            <dd>
                    <xsl:value-of select="$country/country"/>
            </dd>

            <dt>Region</dt>
            <dd>
                    <xsl:value-of select="$region/region"/>
            </dd>

            <dt>City</dt>
            <dd>
                    <xsl:value-of select="$city/city"/>
            </dd>

            <dt>Area</dt>
            <dd>
                    <xsl:value-of select="$area/area"/>
            </dd>

            <dt>Location</dt>
            <dd>
                    <xsl:value-of select="$location/title"/>
            </dd>
    </dl>
</xsl:for-each>

Thank you so much for the clear and detailed instructions!

I managed to get it working exactly as I wanted using your code.

Thanks again.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details