4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<?xml version="1.0"?>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<!--
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Licensed to the Apache Software Foundation (ASF) under one or more
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster contributor license agreements. See the NOTICE file distributed with
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster this work for additional information regarding copyright ownership.
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster The ASF licenses this file to You under the Apache License, Version 2.0
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster (the "License"); you may not use this file except in compliance with
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster the License. You may obtain a copy of the License at
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster http://www.apache.org/licenses/LICENSE-2.0
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Unless required by applicable law or agreed to in writing, software
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster distributed under the License is distributed on an "AS IS" BASIS,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster See the License for the specific language governing permissions and
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster limitations under the License.
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster-->
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<xsl:stylesheet version="1.0"
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<!-- O(log(n)) (stack usage!) string reverter -->
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<xsl:template name="string-reverse">
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<xsl:param name="string"/>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<xsl:variable name="length" select="string-length($string)"/>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<xsl:choose>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<xsl:when test="$length &lt; 2">
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster <xsl:value-of select="$string"/>
</xsl:when>
<xsl:when test="$length = 2">
<xsl:value-of select="concat(substring($string, 2, 1), substring($string, 1, 1))"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="middle" select="floor($length div 2)"/>
<xsl:call-template name="string-reverse">
<xsl:with-param name="string" select="substring($string, $middle + 1, $middle + 1)"/>
</xsl:call-template>
<xsl:call-template name="string-reverse">
<xsl:with-param name="string" select="substring($string, 1, $middle)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- /string-reverse -->
</xsl:stylesheet>