Search

I have a list on a site I am working on which displays a list of all authors (based on a custom field called “Byline” which I created) and then renders a page with their entries. On the page of entries by “$byline” I am trying to make a header at the top of the page that says “Entries by [Author]”, but when I put this:

<h3>Entries by <xsl:value-of select="$byline"/></h3>

Instead of putting “Entries by Aram David” it puts “Entries by aram-david”

What I want, I think, is the “handle” of the $byline field… right? Does anyone know how I might achieve this?

It should actually be the opposite. The handle is a normalised version of a text field that can be used for URLs. If you have a field called “Byline” your XML should look something like:

<byline handle="aram-david">Aram David<byline>

So to show that you need to output the value of the node rather than the value of the handle.

What;s the field type, Aram? Can you post your XML?

Well, the whole idea is that I want the page to dynamically report what it is displaying. For instance, if I was an author of an entry, and you clicked on the page that filters entries by author (and were on my page) it would say:

<h3>Entries by Aram David</h3>

but if someone else was, it would say:

<h3>Entries by [such and such person]</h3>

It knows who the author is for this page of results, because it is filtering by the $byline field.

This is the code for the page:

http://pastie.org/490949

Notice this part where I want the name of the name of the field it is filtering by to show:

<h3>Entries by <xsl:value-of select="$byline"/></h3>

Can you also post the XML you are transforming? I take it byline is a URL parameter you are passing to the page?

If the text “Aram David” doesn’t exist in your page XML, then you will probably need a second Data Source attached to the page to filter the Authors section using the byline parameter, which will return more information about that author.

So assuming the Data Source is called “Author Information” and filters out only one Author:

<xsl:value-of select="author-information/entry/name"/>

Here is the XML:

http://pastie.org/491302

It is pulling a LOT of information, I think for each byline… The “Value” is there.. I wonder if that can be brought in?

Hmm. Has the look of something that could be refactored to be cleaner and more lightweight.

As nickdunn mentions, to make it all filter dynamically, you’ll have to use a URL parameter. It appears from your first post you’re already doing that (you used $byline). But the URL param is necessarily the tokenized version, so that’s not what you want to use. You want to use the value from the XML instead. With your current XML, it exists in two places, so you could do either:

<h3>Entries by <xsl:value-of select="//authorlist/byline/@value"/></h3>

or

<h3>Entries by <xsl:value-of select="//authorlist/byline/entry/byline"/></h3>

But as I suggested above, this could potentially get cleaned up first. If you need help, shoot me an email.

Thanks Craig… I definitely don’t want to bug you too much with stuff, you have already helped me tremendously with this project (and Paul, who is working on it with me).

The one weird thing here is that the solution you provided works, and gives the name properly formatted, but it is giving the wrong one. It is giving the first name in the list of authors (byline field), but not the one that is currently showing results on the page.

with the xml you have, aram, what craig suggested will default to the first byline/entry/byline element it reaches since there are multiple numbers of them.

how do you get to a particular page with the authors name? is it via an article link or a link of the author? if it’s the author’s name, then you should be able to filter by that value from the list of params symphonay spits out. if it’s the former, than you should be able to associate the author with the article and extract it from the article instead.

Maybe something like this:

<h3>Entries by <xsl:value-of select="//authorlist/byline[@handle = $byline]/@value"/></h3>

or

<h3>Entries by <xsl:value-of select="//authorlist/byline[@handle = $byline]/entry/byline"/></h3>

Yeah, angelo’s code should work. But if you’re passing a URL param you should theoretically be able to filter out all the non-relevant entries (which is what I meant by cleanup). Unless I’m misunderstanding what you’re trying to do here…

You’ll want to filter your results either in your XSLT template by using the appropriate XPath expression, or in your data source by filtering the results by a URL parameter. If you are listing all the authors and their entries on the page, it makes sense to have the full authorlist XML. If not, you should filter your results in the data source to optimize performance of the page. There’s no need to have such a long list of authors in the XML if you only need to display one.

If the $byline parameter is a URL parameter in your page configuration, you can filter the XML by using an XPath expression to select a specific node and display its value. To be more specific in your node selection, use a predicate (in square brackets) to limit the selected node-set.

As I was writing this, angelo and czheng provided the XPath expressions I was going to suggest.

Hey everyone.. thank you so much for all the help.

<h3>Entries by <xsl:value-of select="//authorlist/byline[@handle = $byline]/@value"/></h3>

Seems to work perfectly!

I am not sure why we are pulling in so much data in the XML. We got some help with it and might not have explained properly what we were doing.. we are really new at this stuff. All that XML should be doing, I think, is pulling just the one author and all their stories. I worry that cleaning this up might be a big job.

All you really need then is a different data source. Keep the authorlist data source for cases where you need to associate a list of entries with their authors.

Create a new data source called “Author” for displaying a single author that is filtered by the $byline URL parameter.

The data source could have the following preferences:

Essentials

  • Name: Author
  • Source: Authors

Filter Results

  • Byline (input field): Value: {$byline}

Sorting and Limiting

  • Sort By: Date
  • Sort Order: descending
  • Show a Maximum of 1 results
  • Show Page 1 of results
  • Required URL Parameter: $byline
  • Redirect to 404 page when no results are found: no

Output Options

  • Parameter Output: Use Field: (None)
  • XML Output: Group By: (None)
  • Included Elements: byline

Then, attach this data source to the page. You should find that this data source will find no records when the $byline URL parameter has no value. When the $byline parameter does have a value, the XML output will include only the author that matches the $byline parameter.

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