How to sort a section by a field from another section (for translated navigation)
This is an open discussion with 7 replies, filed under XSLT.
Search
Have you tried using the <xsl:sort /> element with your <xsl:apply-templates />, if that’s what you use?
Sample data I need produce navigation list sorted by “Sequence number” with translations by “Sections” entries for some “$url-hl” containg the language code. I really do not know how to produce it. Does xsl:sort help in this case? I use xsl:call-template. Here is the XSLT code. The only thing I need to add is sorting by the “Sequence numbers”.
I have got an petite idea. What if I used xsl:copy-of and combined all the three involving sections together? I mean what if I combined “Sections”, “Navigation” and “Sections keys” together at first, then I could xsl:sort them by any field I like? What do you mean? Isn’t it overkill? I mean, if there was some simpler way…
You provided your XSLT above. It would make it easier for someone to help if you also posted all the XML that is relevant.
I think since they are different node sets I would apply-templates on the section keys using xsl:sort for sorting by the sequence number. Then you’d call-template or apply-template on what you really want to output, based on the current sequence number.
But if the section keys does not represent the hierarchy of the pages in any way this will be very tricky.
It’s a bit of a complex solution, and I haven’t quite wrapped my mind around all the pieces of it…
Here is the full XML.
@froded: Indeed, the “Section keys” has nothing to do with the real hierarchy. It’s main purpose is to maintain “keys” for translations of section names and the “Sequence numbers” for the sorting/ordering of the translated section names, because it’s clear such data like the navigational data can not be sorted by DS (very likely resulting in unwanted order). Such sort of data simply must be “pre-sorted”, thus the existence of the “Sequence numbers”.
Create an account or sign in to comment.
Hello.
I got two sections (well, three, but the third “Language keys” does not involve in this problem) and a “Navigation” DS as described below:
I created XSLT to go through “Navigation” replacing the section names by proper translated section names (I used “Recursive Navigation” XSLT utility as my starting point). I works just fine. The problem is I do not know to sort the “Navigation” by the “Section keys / Sequence number” to keep the navigation statically sorted the way I need it to appear on the website. Any ideas? This is, I hope, one of the last problems I got to create my fully multi-lingual website.