Hi all -
I'm attempting to pull a list of unique text entries from an XML document "the jQuery way" and am hitting a wall.
From this XML:
<items>
<item>
<categories>
<cat>Category 1</cat>
<cat>Category 2</cat>
</categories>
</item>
<item>
<categories>
<cat>Category 2</cat>
<cat>Category 3</cat>
</item>
</items>
I'd like to generate a select list like:
<select>
<option>Category 1</option>
<option>Category 2</option>
<option>Category 3</option>
</select>
So far all of my attempts produce a duplicate "Category 2" option node. I attempted to make use of the $.unique() method, but the results make me think it's only comparing the node name, not the text content. Here is my latest hackery that does not work:
var filters = $("cat",xmldoc);
filters = $.unique(filters);
$(filters).each(function()
{
$("select").append("<option>" + $(this).text() + "</option>");
});
I can think of a number of standard javascript tricks to make this happen, but am hoping there's a nice, elegant jQuery way to pull this off.
Any tips or tricks would be greatly appreciated.
Thanks!