Commit ab48bd82 authored by Naoki Kambe's avatar Naoki Kambe
Browse files

[917] fix incorrection in XSD and XSL

parent ecf9f48f
......@@ -485,15 +485,15 @@ class StatsHttpd:
if type(stats_spec) is dict:
# assumed module_spec
if 'item_name' not in stats_spec:
alltag = xml.etree.ElementTree.Element("all")
for mod in stats_spec.keys():
elem = xml.etree.ElementTree.Element(
"element", { "name" : mod })
complextype = xml.etree.ElementTree.Element("complexType")
alltag = xml.etree.ElementTree.Element("all")
stats_spec2xsd(stats_spec[mod], alltag)
complextype = xml.etree.ElementTree.Element("complexType")
complextype.append(alltag)
elem = xml.etree.ElementTree.Element(
"element", { "name" : mod })
elem.append(complextype)
xsd_elem.append(elem)
complextype.append(alltag)
elem.append(complextype)
xsd_elem.append(elem)
# assumed stats_spec
else:
if stats_spec['item_type'] == 'map':
......@@ -617,22 +617,22 @@ class StatsHttpd:
xsl_elem.append(table)
# assumed stats_spec
else:
#tr = xml.etree.ElementTree.Element("tr")
tr = xml.etree.ElementTree.Element("tr")
td = xml.etree.ElementTree.Element("td")
td.text = stats_spec["item_name"]
xsl_elem.append(td)
td = xml.etree.ElementTree.Element("td")
tr.append(td)
if stats_spec['item_type'] == 'map':
stats_spec2xsl(stats_spec['map_item_spec'], td)
stats_spec2xsl(stats_spec['map_item_spec'], tr)
elif stats_spec['item_type'] == 'list':
stats_spec2xsl(stats_spec['list_item_spec'], td)
stats_spec2xsl(stats_spec['list_item_spec'], tr)
else:
td = xml.etree.ElementTree.Element("td")
xsl_valueof = xml.etree.ElementTree.Element(
"xsl:value-of",
attrib={'select': stats_spec["item_name"]})
td.append(xsl_valueof)
#tr.append(td)
xsl_elem.append(td)
tr.append(td)
xsl_elem.append(tr)
# multiple stats_specs
elif type(stats_spec) is list:
table = xml.etree.ElementTree.Element("table")
......@@ -644,10 +644,8 @@ class StatsHttpd:
th.text = "Values"
tr.append(th)
table.append(tr)
tr = xml.etree.ElementTree.Element("tr")
for item_spec in stats_spec:
stats_spec2xsl(item_spec, tr)
table.append(tr)
stats_spec2xsl(item_spec, table)
xsl_elem.append(table)
return None
......@@ -656,7 +654,10 @@ class StatsHttpd:
xsd_root = xml.etree.ElementTree.Element( # started with xml:template tag
"xsl:template",
attrib={'match': "bind10:statistics"})
stats_spec2xsl(stats_spec, xsd_root)
if module_name is not None and item_name is not None:
stats_spec2xsl([ stats_spec ] , xsd_root)
else:
stats_spec2xsl(stats_spec, xsd_root)
# The coding conversion is tricky. xml..tostring() of Python 3.2
# returns bytes (not string) regardless of the coding, while
# tostring() of Python 3.1 returns a string. To support both
......
......@@ -160,7 +160,6 @@ class TestHttpHandler(unittest.TestCase):
self.assertIsNotNone(root.find(k))
else:
self.assertIsNotNone(root.find(item))
# URL is '/bind10/statistics/xml'
check_XML_URL_PATH(mod=None, item=None)
for m in DUMMY_DATA:
......@@ -223,25 +222,30 @@ class TestHttpHandler(unittest.TestCase):
root = xml.etree.ElementTree.parse(response).getroot()
url_trans = '{http://www.w3.org/1999/XSL/Transform}'
url_xhtml = '{http://www.w3.org/1999/xhtml}'
xslpath = url_trans + 'template/' + url_xhtml + 'tr'
self.assertEqual(root.tag, url_trans + 'stylesheet')
for tr in root.findall(xslpath):
tds = tr.findall(url_xhtml + 'td')
self.assertIsNotNone(tds)
self.assertEqual(type(tds), list)
self.assertTrue(len(tds) > 2)
self.assertTrue(hasattr(tds[0], 'text'))
if mod is None:
self.assertTrue(tds[0].text in DUMMY_DATA)
else:
self.assertTrue(tds[0].text in DUMMY_DATA[mod])
valueof = tds[2].find(url_trans + 'value-of')
self.assertIsNotNone(valueof)
self.assertTrue(hasattr(valueof, 'attrib'))
self.assertIsNotNone(valueof.attrib)
self.assertTrue('select' in valueof.attrib)
self.assertTrue(valueof.attrib['select'] in \
[ tds[0].text+'/'+item for item in DUMMY_DATA[tds[0].text].keys() ])
if item is None and mod is None:
xslpath = url_trans + 'template/' + url_xhtml + 'table/' + url_trans + 'for-each'
for fe in root.findall(xslpath):
self.assertTrue(fe.attrib['select'] in DUMMY_DATA)
for vo in fe.findall(url_xhtml + 'tr/' \
+ url_xhtml + 'td/' \
+ url_xhtml + 'table/' \
+ url_xhtml + 'tr/' \
+ url_xhtml + 'td/' \
+ url_trans + 'value-of/'):
self.assertTrue(vo.attrib['select'] in DUMMY_DATA[fe.attrib['select']])
elif item is None:
xslpath = url_trans + 'template/' \
+ url_xhtml + 'table/' + url_xhtml + 'tr/' + url_xhtml + 'td/' \
+ url_trans + 'value-of'
for vo in root.findall(xslpath):
self.assertTrue(vo.attrib['select'] in DUMMY_DATA[mod])
else:
xslpath = url_trans + 'template/' \
+ url_xhtml + 'table/' + url_xhtml + 'tr/' + url_xhtml + 'td/' \
+ url_trans + 'value-of'
for vo in root.findall(xslpath):
self.assertEqual(vo.attrib['select'], item)
# URL is '/bind10/statistics/xsl'
check_XSL_URL_PATH(mod=None, item=None)
......
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