Commit 62809f71 authored by Naoki Kambe's avatar Naoki Kambe
Browse files

[917] add anchor tag in each module and each item in XSL and description in

each item in XSL
parent 08d090b4
......@@ -579,7 +579,7 @@ class StatsHttpd:
def xsl_handler(self, module_name=None, item_name=None):
"""Handler which just returns the body of XSL document"""
def stats_spec2xsl(stats_spec, xsl_elem):
def stats_spec2xsl(stats_spec, xsl_elem, path='.'):
"""Internal use for xsl_handler. Reads stats_spec
specified as first arguments, and modify the xml object
specified as second argument. xsl_elem must be
......@@ -602,10 +602,14 @@ class StatsHttpd:
"xsl:for-each", attrib={ "select" : mod })
tr = xml.etree.ElementTree.Element("tr")
td = xml.etree.ElementTree.Element("td")
td.text = mod
a = xml.etree.ElementTree.Element(
"a", attrib={ "href": urllib.parse.quote(path + "/" + mod) })
a.text = mod
td.append(a)
tr.append(td)
td = xml.etree.ElementTree.Element("td")
stats_spec2xsl(stats_spec[mod], td)
stats_spec2xsl(stats_spec[mod], td,
path + "/" + mod)
tr.append(td)
foreach.append(tr)
table.append(foreach)
......@@ -615,14 +619,21 @@ class StatsHttpd:
tr = xml.etree.ElementTree.Element("tr")
td = xml.etree.ElementTree.Element(
"td",
{ "class" : "title",
"title" : stats_spec["item_description"] })
td.text = stats_spec["item_name"]
attrib={ "class" : "title",
"title" : stats_spec["item_description"] \
if "item_description" in stats_spec \
else "" })
a = xml.etree.ElementTree.Element(
"a", attrib={ "href": urllib.parse.quote(path + "/" + stats_spec["item_name"]) })
a.text = stats_spec["item_name"]
td.append(a)
tr.append(td)
if stats_spec['item_type'] == 'map':
stats_spec2xsl(stats_spec['map_item_spec'], tr)
stats_spec2xsl(stats_spec['map_item_spec'], tr,
path + "/" + stats_spec["item_name"])
elif stats_spec['item_type'] == 'list':
stats_spec2xsl(stats_spec['list_item_spec'], tr)
stats_spec2xsl(stats_spec['list_item_spec'], tr,
path + "/" + stats_spec["item_name"])
else:
td = xml.etree.ElementTree.Element("td")
xsl_valueof = xml.etree.ElementTree.Element(
......@@ -643,7 +654,7 @@ class StatsHttpd:
tr.append(th)
table.append(tr)
for item_spec in stats_spec:
stats_spec2xsl(item_spec, table)
stats_spec2xsl(item_spec, table, path)
xsl_elem.append(table)
return None
......@@ -653,7 +664,9 @@ class StatsHttpd:
"xsl:template",
attrib={'match': "bind10:statistics"})
if module_name is not None and item_name is not None:
stats_spec2xsl([ stats_spec ] , xsd_root)
stats_spec2xsl([ stats_spec ], xsd_root, './' + module_name)
elif module_name is not None:
stats_spec2xsl(stats_spec, xsd_root, './' + module_name)
else:
stats_spec2xsl(stats_spec, xsd_root)
# The coding conversion is tricky. xml..tostring() of Python 3.2
......
......@@ -712,7 +712,7 @@ class TestStatsHttpd(unittest.TestCase):
}
xsl_body1 = self.stats_httpd.open_template(
stats_httpd.XSL_TEMPLATE_LOCATION).substitute(
xsl_string='<xsl:template match="bind10:statistics"><table><tr><th>Module Names</th><th>Items</th></tr><xsl:for-each select="Dummy"><tr><td>Dummy</td><td><table><tr><th>Item Names</th><th>Values</th></tr><tr><td>foo</td><td><xsl:value-of select="foo" /></td></tr></table></td></tr></xsl:for-each></table></xsl:template>',
xsl_string='<xsl:template match="bind10:statistics"><table><tr><th>Module Names</th><th>Module Items</th></tr><xsl:for-each select="Dummy"><tr><td><a href="./Dummy">Dummy</a></td><td><table><tr><th>Item Names</th><th>Item Values</th></tr><tr><td class="title" title="foo is bar"><a href="./Dummy/foo">foo</a></td><td><xsl:value-of select="foo" /></td></tr></table></td></tr></xsl:for-each></table></xsl:template>',
xsd_namespace=stats_httpd.XSD_NAMESPACE)
xsl_body2 = self.stats_httpd.xsl_handler()
self.assertEqual(type(xsl_body1), str)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment