Search

I'm trying to build a site with the following structure:

  • $root/products shows a list of product categories
  • $root/products/cat shows a list of products (with some details) in category 'cat'
  • $root/products/cat/entry shows more details for product 'entry'

At the moment I'm doing this using an xsl:choose:

<xsl:choose>
    <xsl:when test="$entry">
        <xsl:apply-templates select="products">
            <xsl:with-param name="extended" select="true"/>
        </xsl:apply-templates>
    </xsl:when>
    <xsl:when test="$cat">
        <xsl:apply-templates select="products"/>
    </xsl:when>
    <xsl:otherwise>
        <xsl:apply-templates select="categories">
            <xsl:with-param name="use-images">yes</xsl:with-param>
        </xsl:apply-templates>
    </xsl:otherwise>
</xsl:choose>

So I'm passing a few parameters around to get the desired behaviour. In my products template I then pass the parameter down another level:

<xsl:template match="products">
    <xsl:apply-templates select="entry">
        <xsl:with-param name="extended" select="$extended"/>
    </xsl:apply-templates>
</xsl:template>

This seems a little complex and I've reached the point where I'm wondering if I'm doing the right thing. I've got several data sources:

  • categories is a list of all categories
  • current-category just sets the $ds-current-category to the ID of the current category if $cat is set
  • products is a list of products in the current category (uses $ds-current-category)

I think I'll need another data source to get the current product if $entry is set. That's quite a few data sources, often unused.

Does anyone have any opinions on this approach? Am I going mad?!

The alternative approach that I am thinking of is as follows:

  • $root/products shows a list of product categories
  • $root/products/c/cat shows a list of products (with some details) in category 'cat'
  • $root/products/p/entry shows more details for product 'entry'

In other words I would have two more pages with 'c' and 'p' handles to simply the XSL and data sources.

Thoughts would be appreciated!

Woo hoo! After about twenty attempts I finally got my code to show up properly. I can't get my head around Markdown.

No need to write actual HTML to output your code. Simply append at the beginning of each line 4 spaces or a tab character to turn it into a code block.

If you want to output inline code, you can do so by wrapping the code in question with back ticks (`).

Tried that, didn't work unfortunately. Couldn't work out why so gave up in the end.

I've edited your thread using the Markdown code formatting syntax. Check your thread out and see if that clears anything up for you.

With the line, <xsl:with-param name="extended" select="true"/>. I assume you want to pass in the value true to $extended. If this is the case, the line should read:

<xsl:with-param name="extended" select="'true'"/>

Notice the single quotes around true. Without single quotes, you are asking XSLT to assign the content inside the node <true> to $extended.

Have you considered using modes with your template?

<xsl:apply-templates select="products" mode="extended">

and

<xsl:template match="products" mode="extended">
    ...
</xsl:template>

Regarding the Markdown issue, I think the problem was that I did not leave a blank line between the paragraph and the code block.

Like this.

I'll try using modes, that's a good idea. Still concerned about the number of data sources though, perhaps unnecessarily.

Thanks!

I don't think you necessarily need another step to pass your products template down to the entry. You can simply try this:

<xsl:apply-templates select="products/entry">
    <xsl:with-param name="extended" select="'true'" />
</xsl:apply-templates>

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