Search

I have a project in which I have two related entities, Promo and Hotel with the following ER structure:

  • A Promo belongs to one and only one Hotel
  • A Hotel has zero or more Promos

I have two datasources: promos and hotels. I am filtering the hotels based on the promo's hotel system id, and everything is fine but the resulting XML. The entries are separated, Promos and Hotels are in separated branches, but I needed them to be in the same one grouped by Promo. For instance:

<promos> <entry> <!-- Promo stuff --> <hotel> <!-- Hotel stuff --> </hotel> </entry> </promos>

I can indeed include the hotel field in the promos datasource, but that only adds the single selected field to the XML.

Right now I'm thinking XSL manual transformation is the way to go, but that will add even more processing time since I'm transforming my XML to JSON already.

You probably won't get around doing some XSLT when working with symphony, even if you're just aiming for outputting JSON.

I have built some XML-APIs doing somehow the same as what you're trying to achieve and as soon as datasource-chaining comes into play you most likely have to build your own template that forms the output the way you want - especially if you want to combine different sources into one node.

But as far as I can tell processing-time used by xslt-templates isn't quite worth the mention. It's pretty fast, even on shared hosting environments.

If you really want to avoid XSLT by all means you could give Association Output a try - it includes associated data directly into the parent-datasource, so it might be able to serve you pretty well for your current usecase. You need to be running Symphony 2.5 or newer for that and you have to use Association Field for associations.

But I'd still recommend getting into XSLT - it's worth it and offers much more flexibility!

Grouping in XSLT can be extremely fast if you use keys (i.e. <xsl:key/> elements and the key() function).

Grouping in XSLT can be extremely fast if you use keys (i.e. <xsl:key/> elements and the key() function).

Yes, keys are great in these cases.

Thanks for the advice. I'll go for the XSLT option. I was just concerned by the time taken to process the XML into organized XML and then into JSON.

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