1<?xml version="1.0" encoding='iso-8859-1'?> 2 3<!-- this stylesheet looks the first a element (html anchor) whose 4 name attribute starts with the string 'prefix_', then copies this 5 anchor to the beginning of the document (right after the body 6 start tag) and removes the anchor element from the original 7 place. the rest of the input is copied identically. --> 8 9<xsl:stylesheet version="1.0" 10 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 11 xmlns:html="http://www.w3.org/TR/REC-html40" > 12 13 <xsl:template match="@*|node()"> 14 <xsl:copy> 15 <xsl:apply-templates select="@*|node()"/> 16 </xsl:copy> 17 </xsl:template> 18 19 <xsl:template name="beginning-of-body" > 20 <xsl:variable name="first-anchor" select="//html:a[starts-with 21(@name, 'prefix_')][1]/@name" /> 22 <xsl:if test="$first-anchor" > 23 <a name="{$first-anchor}" /> 24 </xsl:if> 25 </xsl:template> 26 27 <xsl:template match="//html:a[starts-with(@name, 'prefix_')][not 28(preceding::html:a[starts-with(@name, 'prefix_')])]" > 29 <xsl:apply-templates select="node()" /> 30 </xsl:template> 31 32 <xsl:template match="html:body" > 33 <xsl:copy> 34 <xsl:call-template name="beginning-of-body" /> 35 <xsl:apply-templates select="@*|node()" /> 36 </xsl:copy> 37 </xsl:template> 38 39 40 <!-- 41 * Licensed to the Apache Software Foundation (ASF) under one 42 * or more contributor license agreements. See the NOTICE file 43 * distributed with this work for additional information 44 * regarding copyright ownership. The ASF licenses this file 45 * to you under the Apache License, Version 2.0 (the "License"); 46 * you may not use this file except in compliance with the License. 47 * You may obtain a copy of the License at 48 * 49 * http://www.apache.org/licenses/LICENSE-2.0 50 * 51 * Unless required by applicable law or agreed to in writing, software 52 * distributed under the License is distributed on an "AS IS" BASIS, 53 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 54 * See the License for the specific language governing permissions and 55 * limitations under the License. 56 --> 57 58</xsl:stylesheet> 59