This is for a school project where we students have to do various things with XML files. This is the XML file given:
<?xml version="1.0" encoding="UTF-8"?>
<en_iso>
<norms>
<norm identifier="iso_13857" name="EN ISO 13857">
<keyword>Security</keyword>
<keyword>Engines</keyword>
<replaces/>
</norm>
<norm identifier="iso_13849_1" name="EN ISO 13849-1">
<keyword>Security</keyword>
<keyword>Engines</keyword>
<keyword>Controlling</keyword>
<replaces idref="iso_13857"/>
</norm>
</norms>
<pubs>
<pub>
<title>Norms for Engine Security</title>
<filename>caise2011sgln.pdf</filename>
<normref idref="iso_13857"/>
<normref idref="iso_13849_1"/>
</pub>
<pub>
<title>Setting up Complex Engines</title>
<filename>coopis2012sln.pdf</filename>
<normref idref="iso_13849_1"/>
</pub>
</pubs>
</en_iso>
So this XML contains a list of elements and another list of elements, referencing the former list. Specifically a list of ISO norms and a separate list of publications referencing one or many of the norms given.
We had to create an XSD, we had to use XPath and do some XSLT with the source XML. The last "bonus" part of the project would be to "come up with a creative idea on your own".
My idea: I would like to create an HTML file and populate a dropdown with the norms names from the XML using jquery. I would then like to fill a SPAN (or similar) with the filename(s) of the publications relevant to a norm selected in the dropdown.
Kind of like:
Norm:
[EN ISO 13849-1]
Files:
caise2011sgln.pdf
coopis2012sln.pdf
or
Norm:
[EN ISO 13857]
Files:
caise2011sgln.pdf
I tried to hack together some samples from the web and from here, for example dynamic load data from xml to drop down box with jquery or create drop down dynamically from xml but only ever got the dropdown to populate - if at all - but never managed to have the filenames displayed at all. I'm at a loss here.
This is the current HTML with only the dropdown working:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "GET",
url: "source.xml",
dataType: "xml",
success: function (result) {
$(result).find("norm").each(function () {
$("#norms").append($("<option />").val($(this).attr("identifier")).text($(this).attr("name")));
});
}
});
});
</script>
Norm::
<select id="norms"></select><br>
Publications:
<span id="publications"><!-- filenames --></span>
</body>
</html>
Many thanks in advance for any help