Revision 886
Added by Aaron Marcuse-Kubitza about 13 years ago
map | ||
---|---|---|
154 | 154 |
def get_value(in_, row): |
155 | 155 |
pkey, = row |
156 | 156 |
in_ = in_.cloneNode(True) # don't modify orig value! |
157 |
xml_dom.set_id(xpath.get(in_, in_root), pkey) |
|
157 |
xml_dom.set_id(xpath.get(in_, in_root)[0], pkey)
|
|
158 | 158 |
value = sql.value_or_none(db_xml.get(in_db, in_, in_pkeys)) |
159 | 159 |
if value != None: return str(value) |
160 | 160 |
else: return None |
... | ... | |
163 | 163 |
in_db.close() |
164 | 164 |
elif in_is_xml: |
165 | 165 |
def get_value(in_, row): |
166 |
node = xpath.get(row, in_) |
|
167 |
if node != None: return xml_dom.value(node)
|
|
166 |
nodes = xpath.get(row, in_)
|
|
167 |
if nodes != []: return xml_dom.value(nodes[0])
|
|
168 | 168 |
else: return None |
169 |
row0 = xpath.get(doc0.documentElement, in_root)
|
|
170 |
if row0 == None: raise SystemExit('Map error: Root "'+in_root
|
|
169 |
rows = xpath.get(doc0.documentElement, in_root)
|
|
170 |
if rows == []: raise SystemExit('Map error: Root "'+in_root
|
|
171 | 171 |
+'" not found in input') |
172 |
map_rows(get_value, xml_dom.NodeElemIter(row0.parentNode))
|
|
172 |
map_rows(get_value, xml_dom.NodeElemIter(rows[0].parentNode))
|
|
173 | 173 |
else: # input is CSV |
174 | 174 |
map_ = dict(mappings) |
175 | 175 |
reader = csv.reader(sys.stdin) |
Also available in: Unified diff
xpath.py: get(): Added full support for returning multiple matches