On 07/16/13 00:52, Jonas Walldén wrote:
Hi Christopher,

Since the document <emit> only gives you pointers to the files you cannot sort directly 
on the titles or whatever property you need. (You can sort on the path itself with the generic 
emit sort capability, i.e. sort="ref", but that's not very useful.)

Instead you need to place the results in a temporary data structure that you 
can sort (e.g. a mapping with titles as keys) and loop through that.

   <set variable="var.fileinfo" type="mapping"/>
   <emit source="category" file="..." node="..." document="">
     <!-- Get file info and place in mapping -->
     <emit source="dir" ...>
       <set variable="var.fileinfo.&_.title;" type="text/*">
         <a href="...">...</a>
       </set>
     </emit>
   </emit>
<!-- Output file info entries sorted on keys -->
   <emit source="values" variable="var.fileinfo" sort="index">
     &_.value:none;
   </emit>

(Note that this example doesn't cope with empty titles since the key isn't unique then. One 
workaround is to build a composite key like "&_.title;|&_.path;" to ensure 
uniqueness and still get the titles in alphabetical order when possible.)

Cheers,

-- Jonas


I wanted to mention, for posterity's sake, that I noticed the category-document emit source, and decided to use that in this fairly simple version of the code:

 <nocache>

    <emit source='category'>

        <ul>

          <emit source='category' file='&_.file;' node='&_.node;' category=''>

            <li>&_.name;

              <ul>

                <emit source='category-document' nodes='category.xml!&_.node;' 
sort='title'>

                  <li><a href="&_.path;">&_.title;</a></li>

                </emit>

              </ul>

            </li>

          </emit>

        </ul>

    </emit>

  </nocache>


This version is not fully recursive, nor does it handle empty titles properly, but neither of these issues are a concern in my particular situation.

<<attachment: cmhoward2.vcf>>

Reply via email to