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