0

I am trying to load my parse my XML document but the HTML page remains null, is there something that I'm doing wrong.

index.html

<script type="text/javascript" src="assets/js/script.js"></script>
<body onLoad="outputXML('content', 'assets/xml/sample.xml', 'assets/xml/sample.xsl');"></body>

script.js

Click here to view the code

sample.xml

<?xml version="1.0" encoding="utf-8"?>
<hitrecords>
  <record genre="Ska">
    <artist category="group" gender="male">Madness</artist>
    <title>Baggy Trousers</title>
    <length>
      <minutes>3</minutes>
      <seconds>30</seconds>
    </length>
  </record>
</hitrecords>

sample.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <xsl:for-each select="hitrecords/record">
            <p>
                <xsl:value-of select="."/>
                <xsl:value-of select="@genre"/> 
                <xsl:value-of select="artist"/> 
            </p>
        </xsl:for-each>
    </xsl:template> 
</xsl:stylesheet>

1 Answer 1

1

I've just tested your example and it's working with the adjustment to add an element with the id="content" to the HTML:

<body onLoad="outputXML('content', 'assets/xml/sample.xml', 'assets/xml/sample.xsl');">
  <div id="content"></div>
</body>

The function outputXML(location, xml, xsl) { ...} that is called with content as value for the parameter location calls the function processXML (location, xml, xsl) { ... }.
This function appends the resultDocument to an element with an id that has the value of location:

document.getElementById(location).appendChild(resultDocument);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.