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
12
* http://www.apache.org/licenses/LICENSE-2.0
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.
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"
27
<xalan:component prefix="counter"
28
elements="init incr" functions="read">
29
<xalan:script lang="javascript">
30
var counters = new Array();
32
function init (xslproc, elem) {
33
name = elem.getAttribute ("name");
34
value = parseInt(elem.getAttribute ("value"));
35
counters[name] = value;
39
function read (name) {
40
return "" + (counters[name]);
43
function incr (xslproc, elem)
45
name = elem.getAttribute ("name");
52
<xsl:template match="/">
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"/>
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"/>
68
<counter:incr name="index"/>