diff --git a/src/calibre/library/server/browse.py b/src/calibre/library/server/browse.py
index 7bc92a6113..9141964193 100644
--- a/src/calibre/library/server/browse.py
+++ b/src/calibre/library/server/browse.py
@@ -155,15 +155,13 @@ def get_category_items(category, items, datatype, prefix): # {{{
'
{1}
'
'{2}
')
rating, rstring = render_rating(i.avg_rating, prefix)
- if i.use_sort_as_name:
- name = xml(i.sort)
- else:
- name = xml(i.name)
+ orig_name = i.sort if i.use_sort_as_name else i.name
+ name = xml(orig_name)
if datatype == 'rating':
name = xml(_('%d stars')%int(i.avg_rating))
id_ = i.id
if id_ is None:
- id_ = hexlify(force_unicode(name).encode('utf-8'))
+ id_ = hexlify(force_unicode(orig_name).encode('utf-8'))
id_ = xml(str(id_))
desc = ''
if i.count > 0:
@@ -675,7 +673,7 @@ class BrowseServer(object):
which = unhexlify(cid).decode('utf-8')
vls = self.db.prefs.get('virtual_libraries', {})
ids = self.search_cache(vls[which])
- category_name = _('virtual library: ') + which
+ category_name = _('virtual library: ') + xml(which)
if not ids:
msg = _('The virtual library %s has no books.') % prepare_string_for_xml(which)
if self.search_restriction: