How to change XML DOM with javascript when using XML + XSLT client side

For instance:

XML:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="example.xsl"?>
<document>
  <foo>bar</foo>
</document>

XSL:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <head>
        <title>example</title>
        <script type="text/javascript">
          /* magic javascript that alters the foo-node to contain something else */
        </script>
      </head>
      <body>
        <p>Foo: <xsl:value-of select="foo" /></p>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

I want javascript to modify the XML DOM, not the HTML DOM!

+3
source share
2 answers

This is impossible, and even if it was possible, I have no idea what you expect from this.

XML is already converted for display, XSLT does not update the view in real time.

The View Source in the browser will only show the source as sent, not the serialization of the DOM as modified.

Debuggers such as Firebug will display DOM serialization as shown in the browser (i.e. the converted DOM, as well as any modified scripts).

+2
source

, . Javascript XSLT , , , XML .

: , Javascript, - HTML <script> . .

XSLT , , - 100K- .

+1

Source: https://habr.com/ru/post/1746393/


All Articles