View Single Post
Old 01-04-2012, 07:21 PM   #27
Krogenar
It's Facebook!
Krogenar began at the beginning.
 
Krogenar's Avatar
 
Posts: 10
Karma: 10
Join Date: Jun 2011
Device: Nook Color
Quote:
Originally Posted by chaley View Post
It seems that you are saying that:
- A book has zero genre values, or 2 or more genre values.
- If a book has a genre value, the first is either FICTION or NONFICTION, and all subsequent values begin with that value.
- If a book has no genre values, then you want an empty value.
- If a book has genre values, then you want the second value in the sorted list.

If the above is true, then this template gives you the value you want.
Code:
{#genre:'re(cmp(count($, ','), 1, '', $,  sublist(list_sort($, '0', ','), 1, 2, ',')), '\.', '/')'||/}{author}/{title}
The template uses template program mode, which permits nesting of function calls. The outermost function, re, operates on the return value of 'cmp', converting all periods to slashes. The cmp function checks the length of the genre list. If it is less than 1, it returns the empty string. If it is equal to 1 (a case that shouldn't happen according to my understanding of the rules), it returns the single value. If it is longer than 1, it sorts the list and returns the second value.
I'm still testing it out, but it seems like you've done it! Thank you so much! Now I just have to tweeze apart what you've written so I can help myself out next time. Thank you. Thank you. Thank you.
Krogenar is offline   Reply With Quote