Hi Aidan,<div><br></div><div>I will try to help. First I'll discuss your issue about sorting according to Reverse elements, then secondly I'll address your "ideal" solution of not duplicating identical Reverse elements.</div>
<div><br></div><div>1. If you want to have all the Reverse elements in the source sorted as a single list, rather than a series of sorted lists, one for each Headword, then I think your problem is that you are doing your sort inside this for-each loop:</div>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<xsl:for-each select="Words[Status!='Exclude']"></blockquote><div>So you need a template structure that goes directly from the whole-dictionary level right to the Reverse elements, rather than getting to them via the Words wrappers. Does that make sense? </div>
<div>Maybe something like:</div><div><br></div><div><xsl:template match="Dictionary"></div><div> <xsl:for-each select="//Reverse"></div><div> <xsl:sort select="."/></div>
<div> <p><b><xsl:value-of select="."/></b></p></div><div> <xsl:value:of select="ancestor::Words/Headword"/> </div><div> </xsl:for-each><br></xsl:template></div>
<div><br></div><div>PS: another way of sorting in xsl is with an attribute @order-by on the <for-each element. I don't know what the difference is between the methods, and it may be arcane.</div><div><br></div><div>
<br></div><div>2. As for de-duplicating the Reverse elements: I don't think XSL is a particularly good tool for it; it's not a very good framework for comparing strings... and when you want to extract wordlists from data, you often get sets of things that are not identical character-by-character, but you would like to have treated as one.</div>
<div><br></div><div>That said, it might work if you have a condition, simply asking at each Reverse element, "have I already displayed a Reverse element like this one?" And if not, then display it, but alongside display not just it's own Headword sibling, but the Headwords of each Reverse elements with that value.</div>
<div> Code could be something like this:</div><div><div><br></div><div><xsl:template match="Dictionary"></div><div> <xsl:for-each select="//Reverse"></div><div> <xsl:sort select="."/></div>
<div> <!-- I'm not sure if you need this variable, but you might need it for the output bit below--></div><div> <xsl:variable name="this_word" select="."/></div><div> <xsl:choose></div>
<div> <xsl:when test="$this_word = ancestor::Words/preceding-sibling::Words//Reverse"></div><div> <!-- no output - we've seen this Reverse before --></div><div> </xsl:when></div>
<div><div> <xsl:otherwise></div><div> <!-- output the Reverse element --></div><div> <p><b><xsl:value-of select="."/></b></p></div><div> <!-- for each Words element that has this Reverse word in it, output the Headword --></div>
<div> <xsl:for-each select="ancestor::Words/preceding-sibling::Words[descendent::Reverse = $this_word] or ancestor::Words/following-sibling::Words[descendent::Reverse = $this_word]"></div><div> <xsl:value:of select="Headword"/> </div>
<div> </xsl:for-each></div><div> </xsl:otherwise></div></div><div> </xsl:for-each><br></xsl:template></div></div><div><br></div><div>I don't know if that will work, but it seems like it should.</div>
<div><br></div><div>j</div><div><br><div class="gmail_quote">On 28 February 2011 15:30, Aidan Wilson <span dir="ltr"><<a href="mailto:a.wilson@pgrad.unimelb.edu.au">a.wilson@pgrad.unimelb.edu.au</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi RNLDers (I still prefer "Ronaldos")<br>
<br>
Does anyone have fairly good XSL skills and could guide me through a particularly nasty dictionary formatting issue?<br>
<br>
The problem is that I have a reverse word finder which is built by extracting an element from each headword ('Reverse' which was originally put in for exactly this purpose). Here's an example of a word's XML (totally made up<br>
example to demonstrate the point):<br>
<br>
<Words><br>
<Headword>elevate</Headword><br>
<Category>verb</Category><br>
<Meanings><br>
<Definition>to raise, to lift</Definition><br>
<Reverse>raise</Reverse><br>
<Reverse>lift</Reverse><br>
<Examples><br>
<Example>You need to elevate your blood pressure</Example><br>
<Translation>You need to raise your blood pressure</Translation><br>
</Examples><br>
</Meanings><br>
</Words><br>
<br>
The difficulty is that some words will have more than one Reverse element (as above). At the moment I can either:<br>
a) Extract only the first reverse element from each entry, display it next to the headword, and all will be in alphabetical order by the Reverse element, or<br>
b) Extract all reverse elements from all headwords, and display each one next to its headword, but they will be ordered *within the set of reverse elements of that word.<br>
<br>
What I mean by that, is that I can get it working so I can produce:<br>
<br>
Lift:<br>
elevate<br>
<br>
Raise:<br>
elevate<br>
<br>
But the Reverse elements from any other words will be sorted amongst themselves, but independently of any other word. So what I get in my English to Wagiman section is essentially ordered by the Wagiman word, but each word's<br>
English glosses sorted among themselves.<br>
<br>
What I would like is to pair each reverse element with its headword and then sort the whole list for the whole dictionary at once.<br>
<br>
Ideally, actually, I'd like to group together identical Reverse elements so that I could have something like:<br>
<br>
Lift:<br>
boost<br>
elevate<br>
heighten<br>
raise<br>
<br>
Instead of listing them separately.<br>
<br>
Here's the relevant section of my xsl stylesheet:<br>
<br>
<xsl:for-each select="Words[Status!='Exclude']"><br>
<xsl:sort select="Meanings/Reverse"/><br>
<xsl:for-each select="Meanings/Reverse"><br>
<p><strong><xsl:value-of select="."/></strong><br/><br>
<xsl:value-of select="../../Headword"/></p><br>
</xsl:for-each><br>
</xsl:for-each><br>
<br>
Hopefully this isn't an impossible task. And hopefully someone knows more than my week's worth of xsl and can point me in the right direction!<br>
<br>
-- <br>
Aidan Wilson<br>
<br>
PhD Candidate<br>
Dept of Linguistics and Applied Linguistics<br>
The University of Melbourne<br>
<br>
+61428 458 969<br>
<a href="mailto:a.wilson@pgrad.unimelb.edu.au" target="_blank">a.wilson@pgrad.unimelb.edu.au</a><br>
</blockquote></div><br></div>