Search

Let's take a SBL+ field (say Images) inside Articles section and an Images DS with a filter set on System ID with the SBL+ output.

Currently I have this XSLT to select the images in order to display:

<xsl:template match="articles-index/entry">
    <xsl:apply-templates select="/data/images-by-id/entry[ @id=current()/images/item/@id ]"/>
</xsl:template>

<xsl:template match="images-by-id/entry">
    ... display image using "." context
</xsl:template>

This iterates through the Images by ID datasource entries and displays the ones matched by Images field from each Article.

Given that the new SBL+ allows sorting of related items, the items in the output of SBL+ fields are arbitrary sorted. I want to take advantage of this so I'm using this XSLT to respect this order:

<xsl:template match="articles-index/entry">
    <xsl:apply-templates select="images/item[ @id=/data/images-by-id/entry/@id ]"/>
</xsl:template>

<xsl:template match="images/item">
    <xsl:variable name="entry" select="/data/images-by-id/entry[ @id=current()/@id ]"/>

    ... display image using $entry variable
</xsl:template>

This iterates through the items from Images field and displays the ones that are found in Images by ID datasource. This is the best I have so far ... Is there a way to set the sorting of images-by-id/entry elements regarding images/item? Something like:

<xsl:apply-templates select="/data/images-by-id/entry[ @id=current()/images/item/@id ]">
    <xsl:sort select="..." />
</xsl:apply-templates>

Thanks.

Do it the other way round. Select all images from your article first:

<xsl:template match="articles-index/entry">
    <xsl:apply-templates select="images/item"/>
</xsl:template>

then fetch all the images from the images DS:

<xsl:template match="images/item">
    <xsl:apply-templates select="/data/images-by-id/entry[@id = current()/@id]" />
</xsl:template>

And display the way you like:

<xsl:template match="images-by-id/entry">
    these are now sorted by their appearance in `images/item`
</xsl:template>

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