xref: /aosp_15_r20/external/apache-xml/test/tests/extensions/javascript/javascriptSample2.xsl (revision 1212f9a0ffdc28482b8821715d2222bf16dc14e2)
1<?xml version="1.0"?>
2<!--Namespaces are global if you set them in the stylesheet element-->
3<xsl:stylesheet
4    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5    version="1.0"
6    xmlns:lxslt="http://xml.apache.org/xslt"
7    xmlns:my-ext="ext2"
8    extension-element-prefixes="my-ext">
9
10<!-- Copied from: java/samples/extensions/5-numlistJscript.xsl -->
11
12  <!--The component and its script are in the lxslt namespace and define the implementation-->
13  <lxslt:component prefix="my-ext" elements="timelapse" functions="getdate">
14    <lxslt:script lang="javascript">
15      var multiplier=1;
16      // Extension element implementations always take two arguments. The first
17      // argument is the XSL Processor context; the second argument is the element.
18      function timelapse(xslProcessorContext, elem)
19      {
20        multiplier=parseInt(elem.getAttribute("multiplier"));
21        // The element return value is placed in the result tree.
22        // If you do not want a return value, return null.
23        return null;
24      }
25      function getdate(numdays)
26      {
27        // Use a constant date so test output is determinate
28        var d = new Date(2001, 8, 5);
29        d.setDate(d.getDate() + parseInt(numdays*multiplier));
30        return d.toLocaleString();
31      }
32    </lxslt:script>
33  </lxslt:component>
34
35  <xsl:template match="deadline">
36  <out>
37    <p><my-ext:timelapse multiplier="2"/>We have received your enquiry and will
38      respond by <xsl:value-of select="my-ext:getdate(string(@numdays))"/></p>
39  </out>
40  </xsl:template>
41
42
43  <!--
44   * Licensed to the Apache Software Foundation (ASF) under one
45   * or more contributor license agreements. See the NOTICE file
46   * distributed with this work for additional information
47   * regarding copyright ownership. The ASF licenses this file
48   * to you under the Apache License, Version 2.0 (the  "License");
49   * you may not use this file except in compliance with the License.
50   * You may obtain a copy of the License at
51   *
52   *     http://www.apache.org/licenses/LICENSE-2.0
53   *
54   * Unless required by applicable law or agreed to in writing, software
55   * distributed under the License is distributed on an "AS IS" BASIS,
56   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
57   * See the License for the specific language governing permissions and
58   * limitations under the License.
59  -->
60
61</xsl:stylesheet>
62