summaryrefslogtreecommitdiffstats
path: root/dom/xslt/tests/browser/bug1309630.sjs
blob: 9a3f464139064c706f19e19f291da083a7f8c201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function handleRequest(request, response) {
  const XSLT = `<?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="#bug"?>
    <xsl:stylesheet id="bug" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template name="f" match="/">
        <xsl:param name="n" select="0" />
        <xsl:apply-templates select="document(concat('${request.path}?', $n))/xsl:stylesheet/xsl:template[@name='f']">
          <xsl:with-param name="n" select="$n + 1"/>
        </xsl:apply-templates>
        <xsl:call-template name="f">
          <xsl:with-param name="n" select="$n + 1"/>
        </xsl:call-template>
      </xsl:template>
    </xsl:stylesheet>`;

  // reset_counter sets the counter to -1.
  if (request.queryString === "reset_counter") {
    setState("base", "-1");
    response.write("");
    return;
  }

  // record_counter makes us store the current value of the counter.
  if (request.queryString === "record_counter") {
    setState("base", getState("counter"));
    response.write("");
    return;
  }

  // get_counter_change returns the difference between the current
  // value of the counter and the value it had when the script was
  // loaded with the record_counter query string.
  if (request.queryString === "get_counter_change") {
    response.write(
      String(Number(getState("counter")) - Number(getState("base")))
    );
    return;
  }

  // The XSLT code calls the document() function with a URL pointing to
  // this script, with the query string set to a counter starting from 0
  // and incremementing with every call of the document() function.
  // The first load will happen either from the xml-stylesheet PI, or
  // with fetch(), to parse a document to pass to
  // XSLTProcessor.importStylesheet. In that case the query string will
  // be empty, and we don't change the counter value, we only care about
  // the loads through the document() function.
  if (request.queryString) {
    setState("counter", request.queryString);
  }

  response.setHeader("Content-Type", "text/xml; charset=utf-8", false);
  response.write(XSLT);
}