Search

Hello,

I have 3 data sources. For example purposes I will call one of them my master data source named “albums”. The other 2 are my sub data sources called “reviews” and “cover-images”. My “reviews” and “cover-images” entries each have a “album” attribute that matches a “album” data source entry.

I’m trying to find a way through xsl to output organized XML with the “reviews” and “coverimages” entries to become organized children nodes of the “albums”.

Please see the link below for an example: http://pastebin.com/mpwUP18D

Any help would be greatly appreciated! I’m familiar using xsl to transform a single data source, but I’ve been trying to figure this one out and I don’t know where to begin.

I think the key might be in creating params based on the album names, then within a for-each i could filter the reviews and cover-images based on my params, but I don’t know how to do that within a loop.

Much thanks!

Matt

Hi Matt,

Your sample source data isn’t a native symphony data source; are you pulling it from elsewhere, or was this just kind of a general example?

edit:

Here it is based on your source data, but the solution will be somewhat different for entries in a Symphony data source. Let me know if you need help with that also

Pastbin

@ashooner - Did you test that? I couldn’t get it to work.

Here is my offering. I put the dashes in for indentation while testing it; I didn’t want to bother with styling. I left the album attribute out of the review and image elements because they are now children of the album elements.

@wisolman: Ran it in txslmate, can’t recall if that uses libxslt or not…

Just as a didactic sidenote, wisolman’s solution is an example of using the procedural features of xslt (named templates and for-each), while mine is more declarative (matching templates).

Nice little example of the different ways you can skin your xml cats.

@ashooner - It turns out that your approach was working for me. I just didn’t know it because it doesn’t show the output in the browser window (at least it doesn’t in Firefox). When I viewed the page source I could see that it was producing the correct results.

This behavior seems to be due to your xml elements being treated as html and the browser not knowing what to do with <album> etc. The output method setting doesn’t appear to affect this behavior.

@ashooner - That worked perfectly for me. Thank you so much! What I posted was just a simplified example. I am working with s Symphony data source and your code definitely helped me understand what was going on.

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