How to manipulate with UL with jQuery in XML+XSL g

2019-03-06 05:02发布

问题:

This is the XML:

<?xml version="1.0"?>
<?xml-stylesheet href="a.xsl" type="text/xsl"?>
<root/>

This is the a.xsl stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns="http://www.w3.org/1999/xhtml"
  version="2.0" exclude-result-prefixes="xs">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
  <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html&gt;</xsl:text>
  <html>
    <head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"/>
      <script>
        $(document).ready(
          function() {
            $('#list').append('<li>foo</li>');
          }
        );
      </script>
    </head>
    <body>
      <ul id='list'>
        <li><a href="http://www.example.com">hi!</a></li>
      </ul>
    </body>
  </html>
</xsl:template>
</xsl:stylesheet>

The page is not updated by this jQuery manipulation. What is wrong? How to fix it?

回答1:

This is how it works instead:

$('#list').html('<li>foo</li>');