Search

I maybe being silly here, but the obvious answer alludes me.

I have two sections, Filling Types and Fillings - For sandwiches ( apologies to those who may be hungry and waiting for their lunch while reading this ). Now I’ve created a datasource for all my fillings, grouped by filling type.

A snippet from the resulting xml is as follows:

       <section id="6" handle="fillings">Fillings</section>
    <filling-type link-id="9" link-handle="cold-filling">
        <entry id="16">
            <name handle="home-cooked-beef">Home Cooked Beef</name>
        </entry>
        <entry id="17">
            <name handle="beef-salad">Beef Salad</name>
        </entry>
.....

Now when I apply-templates to the filling type node, I sorta want an output like ->

Cold Fillings -Beef - Beef Salad

But all I’ve got to work with from the ‘Filling Type’ name is the link-handle which is obviously lowercased and hyphenated.

Outputting the Filling Type in the XML nests it within the < entry > below the < name >, which means I get the filling type with every filling, when I only really need it once.

I dont really want to use a string replace function on the link handle as I dont feel like its right. Am I going about this wrong as it does seem rather silly, as I’m having a similar issue with categories and that is a common feature.

Have a look at DataSource output parameters. Basically, you need your current ds to use Filling type as output parameter (take note of the parameter name, it would be $ds-something). Then create another ds which pulls from Filling type and filter it by $ds-something.

Thanks Alpacaaa, I thought they maybe something along those lines I’d have to do.

In the end I outputted the Filling Type as the datasource output parameter and created a new datasource of Filling Types filtered by this output.

I then looped through these, grabbed the ID of the Filling Type and applied a template to my main data to group them, it works, just sounds a little backwards.

<filling-types>
    <section id="5" handle="filling-types">Filling Types</section>
    <entry id="10">
        <filling-type handle="panini">Panini</filling-type>
    </entry>
    <entry id="9">
        <filling-type handle="cold-filling">Cold Filling</filling-type>
    </entry>
</filling-types>
  • Filtered by $ds-filling-types

Then do this template match on my main output ( show in OP ):

   < xsl:template match="filling-types/entry">
    < xsl:variable name="filling-id" select="@id" />
    < div id="sides" class="aside">

        < h3 class="title"><xsl:value-of select="filling-type" /></h3>

        < ul class="list group">
            <xsl:apply-templates select="/data/fillings/filling-type[@link-id = $filling-id ]/entry/name" />
        </ul>

    </div>
</xsl:template>

Am I doing that right, in collective opinion anyway lol.. Admittedly I’m attacking this quite blindly, need to do a bit more reading and less ‘hammering’

I can’t see anything wrong with that. However I don’t really understand the problem you’re asking help with. Could you post your XML?

@phoque thanks for the interest mate but I think theres bigger problems on the forum for people to apply their energies to :) and, its working.

I’ll do a bit more digging myself to see if I can improve it.

@Ryu - if you don’t mind, please post your XML. That way, others who are having the same problems can learn from it too.

That way, others who are having the same problems can learn from it too.

That and… I simply love playing around with XSLT. :-D

ha fair enough, here it is ( well the important bit anyways ).

http://pastie.org/1336337

If the XML just output something like:

<filling-type link-id="10" link-handle="panini">
**<filling-type-label>Panini</filling-type-label>**
        <entry id="40"> .... </entry>

Just seems a bit of a shame I can get the link-handle but not the correctly formatted value grouped together.

<filling-type link-id="9" link-handle="cold-filling">

From your first post @ryu, what field are you using to group by? A text input field, when grouped by will give you the @handle and @value in the group node. I’m interested to see which field it is, and why it isn’t doing it the same as a core field.

Oh, and what Symphony version are you using?

@Ryu - Try this with the XML you posted…

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" 
  version="1.0" 
  encoding="utf-8" 
  indent="yes"
  omit-xml-declaration="yes"/>

<xsl:template match="/">
    <xsl:apply-templates select="data/fillings/filling-type"/>
</xsl:template>

<xsl:template match="filling-type">
    <xsl:param name="type-id" select="@link-handle"/>
    <h3><xsl:apply-templates select="../../filling-types/entry[filling-type/@handle=$type-id]" mode="type"/></h3>
    <ul>
        <xsl:apply-templates select="entry" mode="filling"/>
    </ul>
</xsl:template>

<xsl:template match="entry" mode="filling">
    <li><xsl:value-of select="name"/></li>
</xsl:template>

<xsl:template match="entry" mode="type">
    <xsl:value-of select="filling-type"/>
</xsl:template>

</xsl:stylesheet>

It will output the following…

<h3>Cold Filling</h3>
<ul>
  <li>Home Cooked Beef</li>
  <li>Beef Salad</li>
  <li>Beef &amp; Onion</li>
  <li>Beef &amp; Mustard</li>
  <li>Chicken Salad</li>
  <li>Chicken Tikka</li>
  <li>Chicken &amp; Bacon</li>
  <li>Chicken &amp; Sweetcorn</li>
  <li>Coronation Chicken</li>
  <li>Chinese Chicken</li>
  <li>Hot n Kicking Chicken</li>
  <li>Cheese Salad</li>
  <li>Cheese &amp; Coleslaw</li>
  <li>Cheese &amp; Pickle</li>
  <li>Cheese Savoury</li>
  <li>Cheese &amp; Bacon</li>
  <li>Tuna Mayo</li>
  <li>Tuna &amp; Sweetcorn</li>
  <li>Prawn Marie Rose</li>
  <li>Prawn With Salad</li>
  <li>Egg Mayo</li>
  <li>Boiled Egg Salad</li>
  <li>Home Cooked Ham</li>
  <li>Ham &amp; Coleslaw</li>
</ul>
<h3>Panini</h3>
<ul>
  <li>Tuna Melt ( Tuna, Melted Cheese, Red Onion</li>
  <li>Chicken, Bacon &amp; Cheese Melt</li>
  <li>Chicken, Pesto, Mozzarella</li>
  <li>Chicken Tikka</li>
  <li>Meatballs &amp; Mozzarella</li>
</ul>

Is this what you are looking for?

@designermonkey its the Select Box Link I believe.

@bzerangue yea that does the trick, its more or less what I had above, although yours is more elegant and easier to understand :)

If you want to limit your datasources to one (which I would) then in the Select Box Link extension /field/field.selctbox_link.php at line 80, change line 80 to the following two lines:

'link-handle' => Lang::createHandle($primary_field['value']),
'value' => $primary_field['value']),

I’m sending a pull request on Github for this too. This will output the value for you as an attribute.

Be sure to General::sanitize() the value in case it contains an ampersand!

Whoops!

Pleased something productive has come out of my trivial conundrum lol

@designermonkey, exactly what I needed really, surprised its not been there from the start or not deemed to be required until now which makes me wonder if theres a reason why?

Anyhow I couldn’t get it to render the additional attribute Value when declared below the Link Handle function, for some reason beyond me. Anyhow I placed it above and it seems to work great :D

                            'value' => General::sanitize($primary_field['value']),
                        'link-handle' => Lang::createHandle($primary_field['value'])),

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