~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xalan-j_2_7_1/samples/extensions/5-numlistJscript.xsl

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0"?>
 
2
 
 
3
  <!--
 
4
   * Licensed to the Apache Software Foundation (ASF) under one
 
5
   * or more contributor license agreements. See the NOTICE file
 
6
   * distributed with this work for additional information
 
7
   * regarding copyright ownership. The ASF licenses this file
 
8
   * to you under the Apache License, Version 2.0 (the  "License");
 
9
   * you may not use this file except in compliance with the License.
 
10
   * You may obtain a copy of the License at
 
11
   *
 
12
   *     http://www.apache.org/licenses/LICENSE-2.0
 
13
   *
 
14
   * Unless required by applicable law or agreed to in writing, software
 
15
   * distributed under the License is distributed on an "AS IS" BASIS,
 
16
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
17
   * See the License for the specific language governing permissions and
 
18
   * limitations under the License.
 
19
  -->
 
20
 
 
21
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
22
                xmlns:xalan="http://xml.apache.org/xalan"
 
23
                xmlns:counter="MyCounter"
 
24
                extension-element-prefixes="counter"
 
25
                version="1.0">
 
26
 
 
27
  <xalan:component prefix="counter"
 
28
                   elements="init incr" functions="read">
 
29
    <xalan:script lang="javascript">
 
30
      var counters = new Array();
 
31
 
 
32
      function init (xslproc, elem) {
 
33
        name = elem.getAttribute ("name");
 
34
        value = parseInt(elem.getAttribute ("value"));
 
35
        counters[name] = value;
 
36
        return null;
 
37
      }
 
38
 
 
39
      function read (name) {
 
40
        return "" + (counters[name]);
 
41
      }
 
42
 
 
43
      function incr (xslproc, elem)
 
44
      {
 
45
        name = elem.getAttribute ("name");
 
46
        counters[name]++;
 
47
        return null;
 
48
      }
 
49
    </xalan:script>
 
50
  </xalan:component>
 
51
 
 
52
  <xsl:template match="/">
 
53
    <HTML>
 
54
      <H1>JavaScript Example.</H1>
 
55
      <counter:init name="index" value="1"/>
 
56
      <p>Here are the names in alphabetical order by last name:</p>
 
57
      <xsl:for-each select="doc/name">
 
58
        <xsl:sort select="@last"/>
 
59
        <xsl:sort select="@first"/>
 
60
        <p>
 
61
        <xsl:text>[</xsl:text>
 
62
        <xsl:value-of select="counter:read('index')"/>
 
63
        <xsl:text>]. </xsl:text>
 
64
        <xsl:value-of select="@last"/>
 
65
        <xsl:text>, </xsl:text>
 
66
        <xsl:value-of select="@first"/>
 
67
        </p>
 
68
        <counter:incr name="index"/>
 
69
      </xsl:for-each>
 
70
    </HTML>
 
71
  </xsl:template>
 
72
 
 
73
</xsl:stylesheet>