[31735] | 1 | <?xml version="1.0"?>
|
---|
| 2 |
|
---|
| 3 | <!-- This file is taken from the XSLT Standard Library as available
|
---|
| 4 | from http://xsltsl.sourceforge.net/. Except for this notice, it
|
---|
| 5 | has not been modified. -->
|
---|
| 6 |
|
---|
| 7 | <xsl:stylesheet version="1.0"
|
---|
| 8 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
---|
| 9 | xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
|
---|
| 10 | xmlns:str="http://xsltsl.org/string"
|
---|
| 11 | extension-element-prefixes="doc str">
|
---|
| 12 |
|
---|
| 13 | <doc:reference xmlns="">
|
---|
| 14 | <referenceinfo>
|
---|
| 15 | <releaseinfo role="meta">
|
---|
[69482] | 16 | $Id: string.xsl 69482 2017-10-28 13:30:36Z vboxsync $
|
---|
[31735] | 17 | </releaseinfo>
|
---|
| 18 | <author>
|
---|
| 19 | <surname>Ball</surname>
|
---|
| 20 | <firstname>Steve</firstname>
|
---|
| 21 | </author>
|
---|
| 22 | <copyright>
|
---|
| 23 | <year>2002</year>
|
---|
| 24 | <year>2001</year>
|
---|
| 25 | <holder>Steve Ball</holder>
|
---|
| 26 | </copyright>
|
---|
| 27 | </referenceinfo>
|
---|
| 28 |
|
---|
| 29 | <title>String Processing</title>
|
---|
| 30 |
|
---|
| 31 | <partintro>
|
---|
| 32 | <section>
|
---|
| 33 | <title>Introduction</title>
|
---|
| 34 |
|
---|
| 35 | <para>This module provides templates for manipulating strings.</para>
|
---|
| 36 |
|
---|
| 37 | </section>
|
---|
| 38 | </partintro>
|
---|
| 39 |
|
---|
| 40 | </doc:reference>
|
---|
| 41 |
|
---|
| 42 | <!-- Common string constants and datasets as XSL variables -->
|
---|
| 43 |
|
---|
| 44 | <!-- str:lower and str:upper contain pairs of lower and upper case
|
---|
| 45 | characters. Below insanely long strings should contain the
|
---|
| 46 | official lower/uppercase pairs, making this stylesheet working
|
---|
| 47 | for every language on earth. Hopefully. -->
|
---|
| 48 | <!-- These values are not enough, however. There are some
|
---|
| 49 | exceptions, dealt with below. -->
|
---|
| 50 | <xsl:variable name="xsltsl-str-lower" select="'abcdefghijklmnopqrstuvwxyzµàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįıijĵķĺļľŀłńņňŋōŏőœŕŗřśŝşšţťŧũūŭůűųŵŷźżžſƃƅƈƌƒƕƙơƣƥƨƭưƴƶƹƽƿDždžLjljNjnjǎǐǒǔǖǘǚǜǝǟǡǣǥǧǩǫǭǯDzdzǵǹǻǽǿȁȃȅȇȉȋȍȏȑȓȕȗșțȝȟȣȥȧȩȫȭȯȱȳɓɔɖɗəɛɠɣɨɩɯɲɵʀʃʈʊʋʒͅάέήίαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώϐϑϕϖϛϝϟϡϣϥϧϩϫϭϯϰϱϲϵабвгдежзийклмнопрстуфхцчшщъыьэюяѐёђѓєѕіїјљњћќѝўџѡѣѥѧѩѫѭѯѱѳѵѷѹѻѽѿҁҍҏґғҕҗҙқҝҟҡңҥҧҩҫҭүұҳҵҷҹһҽҿӂӄӈӌӑӓӕӗәӛӝӟӡӣӥӧөӫӭӯӱӳӵӹաբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆḁḃḅḇḉḋḍḏḑḓḕḗḙḛḝḟḡḣḥḧḩḫḭḯḱḳḵḷḹḻḽḿṁṃṅṇṉṋṍṏṑṓṕṗṙṛṝṟṡṣṥṧṩṫṭṯṱṳṵṷṹṻṽṿẁẃẅẇẉẋẍẏẑẓẕẛạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹἀἁἂἃἄἅἆἇἐἑἒἓἔἕἠἡἢἣἤἥἦἧἰἱἲἳἴἵἶἷὀὁὂὃὄὅὑὓὕὗὠὡὢὣὤὥὦὧὰάὲέὴήὶίὸόὺύὼώᾀᾁᾂᾃᾄᾅᾆᾇᾐᾑᾒᾓᾔᾕᾖᾗᾠᾡᾢᾣᾤᾥᾦᾧᾰᾱᾳιῃῐῑῠῡῥῳⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩabcdefghijklmnopqrstuvwxyz𐐨𐐩𐐪𐐫𐐬𐐭𐐮𐐯𐐰𐐱𐐲𐐳𐐴𐐵𐐶𐐷𐐸𐐹𐐺𐐻𐐼𐐽𐐾𐐿𐑀𐑁𐑂𐑃𐑄𐑅𐑆𐑇𐑈𐑉𐑊𐑋𐑌𐑍'"/>
|
---|
| 51 | <xsl:variable name="xsltsl-str-upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZΜÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽSƂƄƇƋƑǶƘƠƢƤƧƬƯƳƵƸƼǷDŽDŽLJLJNJNJǍǏǑǓǕǗǙǛƎǞǠǢǤǦǨǪǬǮDZDZǴǸǺǼǾȀȂȄȆȈȊȌȎȐȒȔȖȘȚȜȞȢȤȦȨȪȬȮȰȲƁƆƉƊƏƐƓƔƗƖƜƝƟƦƩƮƱƲƷΙΆΈΉΊΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΣΤΥΦΧΨΩΪΫΌΎΏΒΘΦΠϚϜϞϠϢϤϦϨϪϬϮΚΡΣΕАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏѠѢѤѦѨѪѬѮѰѲѴѶѸѺѼѾҀҌҎҐҒҔҖҘҚҜҞҠҢҤҦҨҪҬҮҰҲҴҶҸҺҼҾӁӃӇӋӐӒӔӖӘӚӜӞӠӢӤӦӨӪӬӮӰӲӴӸԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎẐẒẔṠẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸἈἉἊἋἌἍἎἏἘἙἚἛἜἝἨἩἪἫἬἭἮἯἸἹἺἻἼἽἾἿὈὉὊὋὌὍὙὛὝὟὨὩὪὫὬὭὮὯᾺΆῈΈῊΉῚΊῸΌῪΎῺΏᾈᾉᾊᾋᾌᾍᾎᾏᾘᾙᾚᾛᾜᾝᾞᾟᾨᾩᾪᾫᾬᾭᾮᾯᾸᾹᾼΙῌῘῙῨῩῬῼⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏABCDEFGHIJKLMNOPQRSTUVWXYZ𐐀𐐁𐐂𐐃𐐄𐐅𐐆𐐇𐐈𐐉𐐊𐐋𐐌𐐍𐐎𐐏𐐐𐐑𐐒𐐓𐐔𐐕𐐖𐐗𐐘𐐙𐐚𐐛𐐜𐐝𐐞𐐟𐐠𐐡𐐢𐐣𐐤𐐥'"/>
|
---|
| 52 | <xsl:variable name="xsltsl-str-digits" select="'0123456789'"/>
|
---|
| 53 | <!-- space (#x20) characters, carriage returns, line feeds, or tabs. -->
|
---|
| 54 | <xsl:variable name="xsltsl-str-ws" select="' 	
'"/>
|
---|
| 55 |
|
---|
| 56 | <doc:template name="str:to-upper" xmlns="">
|
---|
| 57 | <refpurpose>Make string uppercase</refpurpose>
|
---|
| 58 |
|
---|
| 59 | <refdescription>
|
---|
| 60 | <para>Converts all lowercase letters to uppercase.</para>
|
---|
| 61 | </refdescription>
|
---|
| 62 |
|
---|
| 63 | <refparameter>
|
---|
| 64 | <variablelist>
|
---|
| 65 | <varlistentry>
|
---|
| 66 | <term>text</term>
|
---|
| 67 | <listitem>
|
---|
| 68 | <para>The string to be converted</para>
|
---|
| 69 | </listitem>
|
---|
| 70 | </varlistentry>
|
---|
| 71 | </variablelist>
|
---|
| 72 | </refparameter>
|
---|
| 73 |
|
---|
| 74 | <refreturn>
|
---|
| 75 | <para>Returns string with all uppercase letters.</para>
|
---|
| 76 | </refreturn>
|
---|
| 77 | </doc:template>
|
---|
| 78 |
|
---|
| 79 | <xsl:template name="str:to-upper">
|
---|
| 80 | <xsl:param name="text"/>
|
---|
| 81 |
|
---|
| 82 | <!-- Below exception is extracted from unicode's SpecialCasing.txt
|
---|
| 83 | file. It's the german lowercase "eszett" (the thing looking
|
---|
| 84 | like a greek beta) that's to become "SS" in uppercase (note:
|
---|
| 85 | that are *two* characters, that's why it doesn't fit in the
|
---|
| 86 | list of upper/lowercase characters). There are more
|
---|
| 87 | characters in that file (103, excluding the locale-specific
|
---|
| 88 | ones), but they seemed to be much less used to me and they
|
---|
| 89 | add up to a hellish long stylesheet.... - Reinout -->
|
---|
| 90 | <xsl:param name="modified-text">
|
---|
| 91 | <xsl:call-template name="str:subst">
|
---|
| 92 | <xsl:with-param name="text">
|
---|
| 93 | <xsl:value-of select="$text"/>
|
---|
| 94 | </xsl:with-param>
|
---|
| 95 | <xsl:with-param name="replace">
|
---|
| 96 | <xsl:text>ß</xsl:text>
|
---|
| 97 | </xsl:with-param>
|
---|
| 98 | <xsl:with-param name="with">
|
---|
| 99 | <xsl:text>S</xsl:text>
|
---|
| 100 | <xsl:text>S</xsl:text>
|
---|
| 101 | </xsl:with-param>
|
---|
| 102 | </xsl:call-template>
|
---|
| 103 | </xsl:param>
|
---|
| 104 |
|
---|
| 105 | <xsl:value-of select="translate($modified-text, $xsltsl-str-lower, $xsltsl-str-upper)"/>
|
---|
| 106 | </xsl:template>
|
---|
| 107 |
|
---|
| 108 | <doc:template name="str:to-lower" xmlns="">
|
---|
| 109 | <refpurpose>Make string lowercase</refpurpose>
|
---|
| 110 |
|
---|
| 111 | <refdescription>
|
---|
| 112 | <para>Converts all uppercase letters to lowercase.</para>
|
---|
| 113 | </refdescription>
|
---|
| 114 |
|
---|
| 115 | <refparameter>
|
---|
| 116 | <variablelist>
|
---|
| 117 | <varlistentry>
|
---|
| 118 | <term>text</term>
|
---|
| 119 | <listitem>
|
---|
| 120 | <para>The string to be converted</para>
|
---|
| 121 | </listitem>
|
---|
| 122 | </varlistentry>
|
---|
| 123 | </variablelist>
|
---|
| 124 | </refparameter>
|
---|
| 125 |
|
---|
| 126 | <refreturn>
|
---|
| 127 | <para>Returns string with all lowercase letters.</para>
|
---|
| 128 | </refreturn>
|
---|
| 129 | </doc:template>
|
---|
| 130 |
|
---|
| 131 | <xsl:template name="str:to-lower">
|
---|
| 132 | <xsl:param name="text"/>
|
---|
| 133 |
|
---|
| 134 | <xsl:value-of select="translate($text, $xsltsl-str-upper, $xsltsl-str-lower)"/>
|
---|
| 135 | </xsl:template>
|
---|
| 136 |
|
---|
| 137 | <doc:template name="str:capitalise" xmlns="">
|
---|
| 138 | <refpurpose>Capitalise string</refpurpose>
|
---|
| 139 |
|
---|
| 140 | <refdescription>
|
---|
| 141 | <para>Converts first character of string to an uppercase letter. All remaining characters are converted to lowercase.</para>
|
---|
| 142 | </refdescription>
|
---|
| 143 |
|
---|
| 144 | <refparameter>
|
---|
| 145 | <variablelist>
|
---|
| 146 | <varlistentry>
|
---|
| 147 | <term>text</term>
|
---|
| 148 | <listitem>
|
---|
| 149 | <para>The string to be capitalised</para>
|
---|
| 150 | </listitem>
|
---|
| 151 | </varlistentry>
|
---|
| 152 | <varlistentry>
|
---|
| 153 | <term>all</term>
|
---|
| 154 | <listitem>
|
---|
| 155 | <para>Boolean controlling whether all words in the string are capitalised.</para>
|
---|
| 156 | <para>Default is true.</para>
|
---|
| 157 | </listitem>
|
---|
| 158 | </varlistentry>
|
---|
| 159 | </variablelist>
|
---|
| 160 | </refparameter>
|
---|
| 161 |
|
---|
| 162 | <refreturn>
|
---|
| 163 | <para>Returns string with first character uppcase and all remaining characters lowercase.</para>
|
---|
| 164 | </refreturn>
|
---|
| 165 | </doc:template>
|
---|
| 166 |
|
---|
| 167 | <xsl:template name="str:capitalise">
|
---|
| 168 | <xsl:param name="text"/>
|
---|
| 169 | <xsl:param name="all" select="true()"/>
|
---|
| 170 |
|
---|
| 171 | <xsl:choose>
|
---|
| 172 | <xsl:when test="$all and (contains($text, ' ') or contains($text, ' ') or contains($text, ' '))">
|
---|
| 173 | <xsl:variable name="firstword">
|
---|
| 174 | <xsl:call-template name="str:substring-before-first">
|
---|
| 175 | <xsl:with-param name="text" select="$text"/>
|
---|
| 176 | <xsl:with-param name="chars" select="$xsltsl-str-ws"/>
|
---|
| 177 | </xsl:call-template>
|
---|
| 178 | </xsl:variable>
|
---|
| 179 | <xsl:call-template name="str:capitalise">
|
---|
| 180 | <xsl:with-param name="text">
|
---|
| 181 | <xsl:value-of select="$firstword"/>
|
---|
| 182 | </xsl:with-param>
|
---|
| 183 | <xsl:with-param name="all" select="false()"/>
|
---|
| 184 | </xsl:call-template>
|
---|
| 185 | <xsl:value-of select="substring($text, string-length($firstword) + 1, 1)"/>
|
---|
| 186 | <xsl:call-template name="str:capitalise">
|
---|
| 187 | <xsl:with-param name="text">
|
---|
| 188 | <xsl:value-of select="substring($text, string-length($firstword) + 2)"/>
|
---|
| 189 | </xsl:with-param>
|
---|
| 190 | </xsl:call-template>
|
---|
| 191 | </xsl:when>
|
---|
| 192 |
|
---|
| 193 | <xsl:otherwise>
|
---|
| 194 | <xsl:call-template name="str:to-upper">
|
---|
| 195 | <xsl:with-param name="text" select="substring($text, 1, 1)"/>
|
---|
| 196 | </xsl:call-template>
|
---|
| 197 | <xsl:call-template name="str:to-lower">
|
---|
| 198 | <xsl:with-param name="text" select="substring($text, 2)"/>
|
---|
| 199 | </xsl:call-template>
|
---|
| 200 | </xsl:otherwise>
|
---|
| 201 | </xsl:choose>
|
---|
| 202 | </xsl:template>
|
---|
| 203 |
|
---|
| 204 | <doc:template name="str:to-camelcase" xmlns="">
|
---|
| 205 | <refpurpose>Convert a string to one camelcase word</refpurpose>
|
---|
| 206 |
|
---|
| 207 | <refdescription>
|
---|
| 208 | <para>Converts a string to one lowerCamelCase or UpperCamelCase
|
---|
| 209 | word, depending on the setting of the "upper"
|
---|
| 210 | parameter. UpperCamelCase is also called MixedCase while
|
---|
| 211 | lowerCamelCase is also called just camelCase. The template
|
---|
| 212 | removes any spaces, tabs and slashes, but doesn't deal with
|
---|
| 213 | other punctuation. It's purpose is to convert strings like
|
---|
| 214 | "hollow timber flush door" to a term suitable as identifier or
|
---|
| 215 | XML tag like "HollowTimberFlushDoor".
|
---|
| 216 | </para>
|
---|
| 217 | </refdescription>
|
---|
| 218 |
|
---|
| 219 | <refparameter>
|
---|
| 220 | <variablelist>
|
---|
| 221 | <varlistentry>
|
---|
| 222 | <term>text</term>
|
---|
| 223 | <listitem>
|
---|
| 224 | <para>The string to be capitalised</para>
|
---|
| 225 | </listitem>
|
---|
| 226 | </varlistentry>
|
---|
| 227 | <varlistentry>
|
---|
| 228 | <term>upper</term>
|
---|
| 229 | <listitem>
|
---|
| 230 | <para>Boolean controlling whether the string becomes an
|
---|
| 231 | UpperCamelCase word or a lowerCamelCase word.</para>
|
---|
| 232 | <para>Default is true.</para>
|
---|
| 233 | </listitem>
|
---|
| 234 | </varlistentry>
|
---|
| 235 | </variablelist>
|
---|
| 236 | </refparameter>
|
---|
| 237 |
|
---|
| 238 | <refreturn>
|
---|
| 239 | <para>Returns string with first character uppcase and all remaining characters lowercase.</para>
|
---|
| 240 | </refreturn>
|
---|
| 241 | </doc:template>
|
---|
| 242 |
|
---|
| 243 | <xsl:template name="str:to-camelcase">
|
---|
| 244 | <xsl:param name="text"/>
|
---|
| 245 | <xsl:param name="upper" select="true()"/>
|
---|
| 246 | <!-- First change all 'strange' characters to spaces -->
|
---|
| 247 | <xsl:param name="string-with-only-spaces">
|
---|
| 248 | <xsl:value-of select="translate($text,concat($xsltsl-str-ws,'/'),' ')"/>
|
---|
| 249 | </xsl:param>
|
---|
| 250 | <!-- Then process them -->
|
---|
| 251 | <xsl:param name="before-space-removal">
|
---|
| 252 | <xsl:variable name="firstword">
|
---|
| 253 | <xsl:call-template name="str:substring-before-first">
|
---|
| 254 | <xsl:with-param name="text" select="$string-with-only-spaces"/>
|
---|
| 255 | <xsl:with-param name="chars" select="$xsltsl-str-ws"/>
|
---|
| 256 | </xsl:call-template>
|
---|
| 257 | </xsl:variable>
|
---|
| 258 | <xsl:choose>
|
---|
| 259 | <xsl:when test="$upper">
|
---|
| 260 | <xsl:call-template name="str:to-upper">
|
---|
| 261 | <xsl:with-param name="text" select="substring($firstword, 1, 1)"/>
|
---|
| 262 | </xsl:call-template>
|
---|
| 263 | <xsl:call-template name="str:to-lower">
|
---|
| 264 | <xsl:with-param name="text" select="substring($firstword, 2)"/>
|
---|
| 265 | </xsl:call-template>
|
---|
| 266 | </xsl:when>
|
---|
| 267 | <xsl:otherwise>
|
---|
| 268 | <xsl:call-template name="str:to-lower">
|
---|
| 269 | <xsl:with-param name="text" select="$firstword"/>
|
---|
| 270 | </xsl:call-template>
|
---|
| 271 | </xsl:otherwise>
|
---|
| 272 | </xsl:choose>
|
---|
| 273 |
|
---|
| 274 | <xsl:call-template name="str:capitalise">
|
---|
| 275 | <xsl:with-param name="text">
|
---|
| 276 | <xsl:value-of select="substring($string-with-only-spaces, string-length($firstword) + 2)"/>
|
---|
| 277 | </xsl:with-param>
|
---|
| 278 | <xsl:with-param name="all" select="true()"/>
|
---|
| 279 | </xsl:call-template>
|
---|
| 280 | </xsl:param>
|
---|
| 281 | <xsl:value-of select="translate($before-space-removal,' ','')"/>
|
---|
| 282 | </xsl:template>
|
---|
| 283 |
|
---|
| 284 | <doc:template name="str:substring-before-first" xmlns="">
|
---|
| 285 | <refpurpose>String extraction</refpurpose>
|
---|
| 286 |
|
---|
| 287 | <refdescription>
|
---|
| 288 | <para>Extracts the portion of string 'text' which occurs before any of the characters in string 'chars'.</para>
|
---|
| 289 | </refdescription>
|
---|
| 290 |
|
---|
| 291 | <refparameter>
|
---|
| 292 | <variablelist>
|
---|
| 293 | <varlistentry>
|
---|
| 294 | <term>text</term>
|
---|
| 295 | <listitem>
|
---|
| 296 | <para>The string from which to extract a substring.</para>
|
---|
| 297 | </listitem>
|
---|
| 298 | </varlistentry>
|
---|
| 299 | <varlistentry>
|
---|
| 300 | <term>chars</term>
|
---|
| 301 | <listitem>
|
---|
| 302 | <para>The string containing characters to find.</para>
|
---|
| 303 | </listitem>
|
---|
| 304 | </varlistentry>
|
---|
| 305 | </variablelist>
|
---|
| 306 | </refparameter>
|
---|
| 307 |
|
---|
| 308 | <refreturn>
|
---|
| 309 | <para>Returns string.</para>
|
---|
| 310 | </refreturn>
|
---|
| 311 | </doc:template>
|
---|
| 312 |
|
---|
| 313 | <xsl:template name="str:substring-before-first">
|
---|
| 314 | <xsl:param name="text"/>
|
---|
| 315 | <xsl:param name="chars"/>
|
---|
| 316 |
|
---|
| 317 | <xsl:choose>
|
---|
| 318 |
|
---|
| 319 | <xsl:when test="string-length($text) = 0"/>
|
---|
| 320 |
|
---|
| 321 | <xsl:when test="string-length($chars) = 0">
|
---|
| 322 | <xsl:value-of select="$text"/>
|
---|
| 323 | </xsl:when>
|
---|
| 324 |
|
---|
| 325 | <xsl:when test="contains($text, substring($chars, 1, 1))">
|
---|
| 326 | <xsl:variable name="this" select="substring-before($text, substring($chars, 1, 1))"/>
|
---|
| 327 | <xsl:variable name="rest">
|
---|
| 328 | <xsl:call-template name="str:substring-before-first">
|
---|
| 329 | <xsl:with-param name="text" select="$text"/>
|
---|
| 330 | <xsl:with-param name="chars" select="substring($chars, 2)"/>
|
---|
| 331 | </xsl:call-template>
|
---|
| 332 | </xsl:variable>
|
---|
| 333 |
|
---|
| 334 | <xsl:choose>
|
---|
| 335 | <xsl:when test="string-length($this) < string-length($rest)">
|
---|
| 336 | <xsl:value-of select="$this"/>
|
---|
| 337 | </xsl:when>
|
---|
| 338 | <xsl:otherwise>
|
---|
| 339 | <xsl:value-of select="$rest"/>
|
---|
| 340 | </xsl:otherwise>
|
---|
| 341 | </xsl:choose>
|
---|
| 342 | </xsl:when>
|
---|
| 343 |
|
---|
| 344 | <xsl:otherwise>
|
---|
| 345 | <xsl:call-template name="str:substring-before-first">
|
---|
| 346 | <xsl:with-param name="text" select="$text"/>
|
---|
| 347 | <xsl:with-param name="chars" select="substring($chars, 2)"/>
|
---|
| 348 | </xsl:call-template>
|
---|
| 349 | </xsl:otherwise>
|
---|
| 350 |
|
---|
| 351 | </xsl:choose>
|
---|
| 352 | </xsl:template>
|
---|
| 353 |
|
---|
| 354 | <doc:template name="str:substring-after-last" xmlns="">
|
---|
| 355 | <refpurpose>String extraction</refpurpose>
|
---|
| 356 |
|
---|
| 357 | <refdescription>
|
---|
| 358 | <para>Extracts the portion of string 'text' which occurs after the last of the character in string 'chars'.</para>
|
---|
| 359 | </refdescription>
|
---|
| 360 |
|
---|
| 361 | <refparameter>
|
---|
| 362 | <variablelist>
|
---|
| 363 | <varlistentry>
|
---|
| 364 | <term>text</term>
|
---|
| 365 | <listitem>
|
---|
| 366 | <para>The string from which to extract a substring.</para>
|
---|
| 367 | </listitem>
|
---|
| 368 | </varlistentry>
|
---|
| 369 | <varlistentry>
|
---|
| 370 | <term>chars</term>
|
---|
| 371 | <listitem>
|
---|
| 372 | <para>The string containing characters to find.</para>
|
---|
| 373 | </listitem>
|
---|
| 374 | </varlistentry>
|
---|
| 375 | </variablelist>
|
---|
| 376 | </refparameter>
|
---|
| 377 |
|
---|
| 378 | <refreturn>
|
---|
| 379 | <para>Returns string.</para>
|
---|
| 380 | </refreturn>
|
---|
| 381 | </doc:template>
|
---|
| 382 |
|
---|
| 383 | <xsl:template name="str:substring-after-last">
|
---|
| 384 | <xsl:param name="text"/>
|
---|
| 385 | <xsl:param name="chars"/>
|
---|
| 386 |
|
---|
| 387 | <xsl:choose>
|
---|
| 388 |
|
---|
| 389 | <xsl:when test="contains($text, $chars)">
|
---|
| 390 | <xsl:variable name="last" select="substring-after($text, $chars)"/>
|
---|
| 391 |
|
---|
| 392 | <xsl:choose>
|
---|
| 393 | <xsl:when test="contains($last, $chars)">
|
---|
| 394 | <xsl:call-template name="str:substring-after-last">
|
---|
| 395 | <xsl:with-param name="text" select="$last"/>
|
---|
| 396 | <xsl:with-param name="chars" select="$chars"/>
|
---|
| 397 | </xsl:call-template>
|
---|
| 398 | </xsl:when>
|
---|
| 399 | <xsl:otherwise>
|
---|
| 400 | <xsl:value-of select="$last"/>
|
---|
| 401 | </xsl:otherwise>
|
---|
| 402 | </xsl:choose>
|
---|
| 403 | </xsl:when>
|
---|
| 404 |
|
---|
| 405 | <xsl:otherwise>
|
---|
| 406 | <xsl:value-of select="$text"/>
|
---|
| 407 | </xsl:otherwise>
|
---|
| 408 |
|
---|
| 409 | </xsl:choose>
|
---|
| 410 | </xsl:template>
|
---|
| 411 |
|
---|
| 412 | <doc:template name="str:substring-before-last" xmlns="">
|
---|
| 413 | <refpurpose>String extraction</refpurpose>
|
---|
| 414 |
|
---|
| 415 | <refdescription>
|
---|
| 416 | <para>Extracts the portion of string 'text' which occurs before the first character of the last occurance of string 'chars'.</para>
|
---|
| 417 | </refdescription>
|
---|
| 418 |
|
---|
| 419 | <refparameter>
|
---|
| 420 | <variablelist>
|
---|
| 421 | <varlistentry>
|
---|
| 422 | <term>text</term>
|
---|
| 423 | <listitem>
|
---|
| 424 | <para>The string from which to extract a substring.</para>
|
---|
| 425 | </listitem>
|
---|
| 426 | </varlistentry>
|
---|
| 427 | <varlistentry>
|
---|
| 428 | <term>chars</term>
|
---|
| 429 | <listitem>
|
---|
| 430 | <para>The string containing characters to find.</para>
|
---|
| 431 | </listitem>
|
---|
| 432 | </varlistentry>
|
---|
| 433 | </variablelist>
|
---|
| 434 | </refparameter>
|
---|
| 435 |
|
---|
| 436 | <refreturn>
|
---|
| 437 | <para>Returns string.</para>
|
---|
| 438 | </refreturn>
|
---|
| 439 | </doc:template>
|
---|
| 440 |
|
---|
| 441 | <xsl:template name="str:substring-before-last">
|
---|
| 442 | <xsl:param name="text"/>
|
---|
| 443 | <xsl:param name="chars"/>
|
---|
| 444 |
|
---|
| 445 | <xsl:choose>
|
---|
| 446 |
|
---|
| 447 | <xsl:when test="string-length($text) = 0"/>
|
---|
| 448 |
|
---|
| 449 | <xsl:when test="string-length($chars) = 0">
|
---|
| 450 | <xsl:value-of select="$text"/>
|
---|
| 451 | </xsl:when>
|
---|
| 452 |
|
---|
| 453 | <xsl:when test="contains($text, $chars)">
|
---|
| 454 | <xsl:call-template name="str:substring-before-last-aux">
|
---|
| 455 | <xsl:with-param name="text" select="$text"/>
|
---|
| 456 | <xsl:with-param name="chars" select="$chars"/>
|
---|
| 457 | </xsl:call-template>
|
---|
| 458 | </xsl:when>
|
---|
| 459 |
|
---|
| 460 | <xsl:otherwise>
|
---|
| 461 | <xsl:value-of select="$text"/>
|
---|
| 462 | </xsl:otherwise>
|
---|
| 463 |
|
---|
| 464 | </xsl:choose>
|
---|
| 465 | </xsl:template>
|
---|
| 466 |
|
---|
| 467 | <xsl:template name="str:substring-before-last-aux">
|
---|
| 468 | <xsl:param name="text"/>
|
---|
| 469 | <xsl:param name="chars"/>
|
---|
| 470 |
|
---|
| 471 | <xsl:choose>
|
---|
| 472 | <xsl:when test="string-length($text) = 0"/>
|
---|
| 473 |
|
---|
| 474 | <xsl:when test="contains($text, $chars)">
|
---|
| 475 | <xsl:variable name="after">
|
---|
| 476 | <xsl:call-template name="str:substring-before-last-aux">
|
---|
| 477 | <xsl:with-param name="text" select="substring-after($text, $chars)"/>
|
---|
| 478 | <xsl:with-param name="chars" select="$chars"/>
|
---|
| 479 | </xsl:call-template>
|
---|
| 480 | </xsl:variable>
|
---|
| 481 |
|
---|
| 482 | <xsl:value-of select="substring-before($text, $chars)"/>
|
---|
| 483 | <xsl:if test="string-length($after) > 0">
|
---|
| 484 | <xsl:value-of select="$chars"/>
|
---|
| 485 | <xsl:copy-of select="$after"/>
|
---|
| 486 | </xsl:if>
|
---|
| 487 | </xsl:when>
|
---|
| 488 |
|
---|
| 489 | <xsl:otherwise/>
|
---|
| 490 | </xsl:choose>
|
---|
| 491 | </xsl:template>
|
---|
| 492 |
|
---|
| 493 | <doc:template name="str:subst" xmlns="">
|
---|
| 494 | <refpurpose>String substitution</refpurpose>
|
---|
| 495 |
|
---|
| 496 | <refdescription>
|
---|
| 497 | <para>Substitute 'replace' for 'with' in string 'text'.</para>
|
---|
| 498 | </refdescription>
|
---|
| 499 |
|
---|
| 500 | <refparameter>
|
---|
| 501 | <variablelist>
|
---|
| 502 | <varlistentry>
|
---|
| 503 | <term>text</term>
|
---|
| 504 | <listitem>
|
---|
| 505 | <para>The string upon which to perform substitution.</para>
|
---|
| 506 | </listitem>
|
---|
| 507 | </varlistentry>
|
---|
| 508 | <varlistentry>
|
---|
| 509 | <term>replace</term>
|
---|
| 510 | <listitem>
|
---|
| 511 | <para>The string to substitute.</para>
|
---|
| 512 | </listitem>
|
---|
| 513 | </varlistentry>
|
---|
| 514 | <varlistentry>
|
---|
| 515 | <term>with</term>
|
---|
| 516 | <listitem>
|
---|
| 517 | <para>The string to be substituted.</para>
|
---|
| 518 | </listitem>
|
---|
| 519 | </varlistentry>
|
---|
| 520 | <varlistentry>
|
---|
| 521 | <term>disable-output-escaping</term>
|
---|
| 522 | <listitem>
|
---|
| 523 | <para>A value of <literal>yes</literal> indicates that the result should have output escaping disabled. Any other value allows normal escaping of text values. The default is to enable output escaping.</para>
|
---|
| 524 | </listitem>
|
---|
| 525 | </varlistentry>
|
---|
| 526 | </variablelist>
|
---|
| 527 | </refparameter>
|
---|
| 528 |
|
---|
| 529 | <refreturn>
|
---|
| 530 | <para>Returns string.</para>
|
---|
| 531 | </refreturn>
|
---|
| 532 | </doc:template>
|
---|
| 533 |
|
---|
| 534 | <xsl:template name="str:subst">
|
---|
| 535 | <xsl:param name="text"/>
|
---|
| 536 | <xsl:param name="replace"/>
|
---|
| 537 | <xsl:param name="with"/>
|
---|
| 538 | <xsl:param name='disable-output-escaping'>no</xsl:param>
|
---|
| 539 |
|
---|
| 540 | <xsl:choose>
|
---|
| 541 | <xsl:when test="string-length($replace) = 0 and $disable-output-escaping = 'yes'">
|
---|
| 542 | <xsl:value-of select="$text" disable-output-escaping='yes'/>
|
---|
| 543 | </xsl:when>
|
---|
| 544 | <xsl:when test="string-length($replace) = 0">
|
---|
| 545 | <xsl:value-of select="$text"/>
|
---|
| 546 | </xsl:when>
|
---|
| 547 | <xsl:when test="contains($text, $replace)">
|
---|
| 548 |
|
---|
| 549 | <xsl:variable name="before" select="substring-before($text, $replace)"/>
|
---|
| 550 | <xsl:variable name="after" select="substring-after($text, $replace)"/>
|
---|
| 551 |
|
---|
| 552 | <xsl:choose>
|
---|
| 553 | <xsl:when test='$disable-output-escaping = "yes"'>
|
---|
| 554 | <xsl:value-of select="$before" disable-output-escaping="yes"/>
|
---|
| 555 | <xsl:value-of select="$with" disable-output-escaping="yes"/>
|
---|
| 556 | </xsl:when>
|
---|
| 557 | <xsl:otherwise>
|
---|
| 558 | <xsl:value-of select="$before"/>
|
---|
| 559 | <xsl:value-of select="$with"/>
|
---|
| 560 | </xsl:otherwise>
|
---|
| 561 | </xsl:choose>
|
---|
| 562 | <xsl:call-template name="str:subst">
|
---|
| 563 | <xsl:with-param name="text" select="$after"/>
|
---|
| 564 | <xsl:with-param name="replace" select="$replace"/>
|
---|
| 565 | <xsl:with-param name="with" select="$with"/>
|
---|
| 566 | <xsl:with-param name="disable-output-escaping" select="$disable-output-escaping"/>
|
---|
| 567 | </xsl:call-template>
|
---|
| 568 | </xsl:when>
|
---|
| 569 | <xsl:when test='$disable-output-escaping = "yes"'>
|
---|
| 570 | <xsl:value-of select="$text" disable-output-escaping="yes"/>
|
---|
| 571 | </xsl:when>
|
---|
| 572 | <xsl:otherwise>
|
---|
| 573 | <xsl:value-of select="$text"/>
|
---|
| 574 | </xsl:otherwise>
|
---|
| 575 | </xsl:choose>
|
---|
| 576 | </xsl:template>
|
---|
| 577 |
|
---|
| 578 | <doc:template name="str:count-substring" xmlns="">
|
---|
| 579 | <refpurpose>Count Substrings</refpurpose>
|
---|
| 580 |
|
---|
| 581 | <refdescription>
|
---|
| 582 | <para>Counts the number of times a substring occurs in a string. This can also counts the number of times a character occurs in a string, since a character is simply a string of length 1.</para>
|
---|
| 583 | </refdescription>
|
---|
| 584 |
|
---|
| 585 | <example>
|
---|
| 586 | <title>Counting Lines</title>
|
---|
| 587 | <programlisting><![CDATA[
|
---|
| 588 | <xsl:call-template name="str:count-substring">
|
---|
| 589 | <xsl:with-param name="text" select="$mytext"/>
|
---|
| 590 | <xsl:with-param name="chars" select="'
'"/>
|
---|
| 591 | </xsl:call-template>
|
---|
| 592 | ]]></programlisting>
|
---|
| 593 | </example>
|
---|
| 594 |
|
---|
| 595 | <refparameter>
|
---|
| 596 | <variablelist>
|
---|
| 597 | <varlistentry>
|
---|
| 598 | <term>text</term>
|
---|
| 599 | <listitem>
|
---|
| 600 | <para>The source string.</para>
|
---|
| 601 | </listitem>
|
---|
| 602 | </varlistentry>
|
---|
| 603 | <varlistentry>
|
---|
| 604 | <term>chars</term>
|
---|
| 605 | <listitem>
|
---|
| 606 | <para>The substring to count.</para>
|
---|
| 607 | </listitem>
|
---|
| 608 | </varlistentry>
|
---|
| 609 | </variablelist>
|
---|
| 610 | </refparameter>
|
---|
| 611 |
|
---|
| 612 | <refreturn>
|
---|
| 613 | <para>Returns a non-negative integer value.</para>
|
---|
| 614 | </refreturn>
|
---|
| 615 | </doc:template>
|
---|
| 616 |
|
---|
| 617 | <xsl:template name="str:count-substring">
|
---|
| 618 | <xsl:param name="text"/>
|
---|
| 619 | <xsl:param name="chars"/>
|
---|
| 620 |
|
---|
| 621 | <xsl:choose>
|
---|
| 622 | <xsl:when test="string-length($text) = 0 or string-length($chars) = 0">
|
---|
| 623 | <xsl:text>0</xsl:text>
|
---|
| 624 | </xsl:when>
|
---|
| 625 | <xsl:when test="contains($text, $chars)">
|
---|
| 626 | <xsl:variable name="remaining">
|
---|
| 627 | <xsl:call-template name="str:count-substring">
|
---|
| 628 | <xsl:with-param name="text" select="substring-after($text, $chars)"/>
|
---|
| 629 | <xsl:with-param name="chars" select="$chars"/>
|
---|
| 630 | </xsl:call-template>
|
---|
| 631 | </xsl:variable>
|
---|
| 632 | <xsl:value-of select="$remaining + 1"/>
|
---|
| 633 | </xsl:when>
|
---|
| 634 | <xsl:otherwise>
|
---|
| 635 | <xsl:text>0</xsl:text>
|
---|
| 636 | </xsl:otherwise>
|
---|
| 637 | </xsl:choose>
|
---|
| 638 | </xsl:template>
|
---|
| 639 |
|
---|
| 640 | <doc:template name="str:substring-after-at" xmlns="">
|
---|
| 641 | <refpurpose>String extraction</refpurpose>
|
---|
| 642 | <refdescription>
|
---|
| 643 | <para>Extracts the portion of a 'char' delimited 'text' string "array" at a given 'position'.</para>
|
---|
| 644 | </refdescription>
|
---|
| 645 | <refparameter>
|
---|
| 646 | <variablelist>
|
---|
| 647 | <varlistentry>
|
---|
| 648 | <term>text</term>
|
---|
| 649 | <listitem>
|
---|
| 650 | <para>The string from which to extract a substring.</para>
|
---|
| 651 | </listitem>
|
---|
| 652 | </varlistentry>
|
---|
| 653 | <varlistentry>
|
---|
| 654 | <term>chars</term>
|
---|
| 655 | <listitem>
|
---|
| 656 | <para>delimiters</para>
|
---|
| 657 | </listitem>
|
---|
| 658 | </varlistentry>
|
---|
| 659 | <varlistentry>
|
---|
| 660 | <term>position</term>
|
---|
| 661 | <listitem>
|
---|
| 662 | <para>position of the elements</para>
|
---|
| 663 | </listitem>
|
---|
| 664 | </varlistentry>
|
---|
| 665 | <varlistentry>
|
---|
| 666 | <term>all</term>
|
---|
| 667 | <listitem>
|
---|
| 668 | <para>If true all of the remaining string is returned, otherwise only the element at the given position is returned. Default: false().</para>
|
---|
| 669 | </listitem>
|
---|
| 670 | </varlistentry>
|
---|
| 671 | </variablelist>
|
---|
| 672 | </refparameter>
|
---|
| 673 | <refreturn>
|
---|
| 674 | <para>Returns string.</para>
|
---|
| 675 | </refreturn>
|
---|
| 676 | </doc:template>
|
---|
| 677 |
|
---|
| 678 |
|
---|
| 679 | <xsl:template name="str:substring-after-at">
|
---|
| 680 | <xsl:param name="text"/>
|
---|
| 681 | <xsl:param name="chars"/>
|
---|
| 682 | <xsl:param name="position"/>
|
---|
| 683 | <xsl:param name="all" select='false()'/>
|
---|
| 684 |
|
---|
| 685 | <xsl:choose>
|
---|
| 686 | <xsl:when test='number($position) = 0 and $all'>
|
---|
| 687 | <xsl:value-of select='$text'/>
|
---|
| 688 | </xsl:when>
|
---|
| 689 | <xsl:when test='number($position) = 0 and not($chars)'>
|
---|
| 690 | <xsl:value-of select='$text'/>
|
---|
| 691 | </xsl:when>
|
---|
| 692 | <xsl:when test='number($position) = 0 and not(contains($text, $chars))'>
|
---|
| 693 | <xsl:value-of select='$text'/>
|
---|
| 694 | </xsl:when>
|
---|
| 695 | <xsl:when test='not(contains($text, $chars))'>
|
---|
| 696 | </xsl:when>
|
---|
| 697 | <xsl:when test="number($position) = 0">
|
---|
| 698 | <xsl:value-of select="substring-before($text, $chars)"/>
|
---|
| 699 | </xsl:when>
|
---|
| 700 | <xsl:otherwise>
|
---|
| 701 | <xsl:call-template name="str:substring-after-at">
|
---|
| 702 | <xsl:with-param name="text" select="substring-after($text, $chars)"/>
|
---|
| 703 | <xsl:with-param name="chars" select="$chars"/>
|
---|
| 704 | <xsl:with-param name="all" select="$all"/>
|
---|
| 705 | <xsl:with-param name="position" select="$position - 1"/>
|
---|
| 706 | </xsl:call-template>
|
---|
| 707 | </xsl:otherwise>
|
---|
| 708 | </xsl:choose>
|
---|
| 709 | </xsl:template>
|
---|
| 710 |
|
---|
| 711 | <doc:template name="str:substring-before-at" xmlns="">
|
---|
| 712 | <refpurpose>String extraction</refpurpose>
|
---|
| 713 | <refdescription>
|
---|
| 714 | <para>Extracts the portion of a 'char' delimited 'text' string "array" at a given 'position' </para>
|
---|
| 715 | </refdescription>
|
---|
| 716 | <refparameter>
|
---|
| 717 | <variablelist>
|
---|
| 718 | <varlistentry>
|
---|
| 719 | <term>text</term>
|
---|
| 720 | <listitem>
|
---|
| 721 | <para>The string from which to extract a substring.</para>
|
---|
| 722 | </listitem>
|
---|
| 723 | </varlistentry>
|
---|
| 724 | <varlistentry>
|
---|
| 725 | <term>chars</term>
|
---|
| 726 | <listitem>
|
---|
| 727 | <para>delimiters</para>
|
---|
| 728 | </listitem>
|
---|
| 729 | </varlistentry>
|
---|
| 730 | <varlistentry>
|
---|
| 731 | <term>position</term>
|
---|
| 732 | <listitem>
|
---|
| 733 | <para>position of the elements</para>
|
---|
| 734 | </listitem>
|
---|
| 735 | </varlistentry>
|
---|
| 736 | </variablelist>
|
---|
| 737 | </refparameter>
|
---|
| 738 | <refreturn>
|
---|
| 739 | <para>Returns string.</para>
|
---|
| 740 | </refreturn>
|
---|
| 741 | </doc:template>
|
---|
| 742 |
|
---|
| 743 | <xsl:template name="str:substring-before-at">
|
---|
| 744 | <xsl:param name="text"/>
|
---|
| 745 | <xsl:param name="chars"/>
|
---|
| 746 | <xsl:param name="position"/>
|
---|
| 747 |
|
---|
| 748 | <xsl:choose>
|
---|
| 749 | <xsl:when test="$position <= 0"/>
|
---|
| 750 | <xsl:when test="not(contains($text, $chars))"/>
|
---|
| 751 | <xsl:otherwise>
|
---|
| 752 | <xsl:value-of select='substring-before($text, $chars)'/>
|
---|
| 753 | <xsl:value-of select='$chars'/>
|
---|
| 754 |
|
---|
| 755 | <xsl:call-template name="str:substring-before-at">
|
---|
| 756 | <xsl:with-param name="text" select="substring-after($text, $chars)"/>
|
---|
| 757 | <xsl:with-param name="position" select="$position - 1"/>
|
---|
| 758 | <xsl:with-param name="chars" select="$chars"/>
|
---|
| 759 | </xsl:call-template>
|
---|
| 760 |
|
---|
| 761 | </xsl:otherwise>
|
---|
| 762 | </xsl:choose>
|
---|
| 763 | </xsl:template>
|
---|
| 764 |
|
---|
| 765 | <doc:template name="str:insert-at" xmlns="">
|
---|
| 766 | <refpurpose>String insertion</refpurpose>
|
---|
| 767 | <refdescription>
|
---|
| 768 | <para>Insert 'chars' into "text' at any given "position'</para>
|
---|
| 769 | </refdescription>
|
---|
| 770 | <refparameter>
|
---|
| 771 | <variablelist>
|
---|
| 772 | <varlistentry>
|
---|
| 773 | <term>text</term>
|
---|
| 774 | <listitem>
|
---|
| 775 | <para>The string upon which to perform insertion</para>
|
---|
| 776 | </listitem>
|
---|
| 777 | </varlistentry>
|
---|
| 778 | <varlistentry>
|
---|
| 779 | <term>position</term>
|
---|
| 780 | <listitem>
|
---|
| 781 | <para>the position where insertion will be performed</para>
|
---|
| 782 | </listitem>
|
---|
| 783 | </varlistentry>
|
---|
| 784 | <varlistentry>
|
---|
| 785 | <term>with</term>
|
---|
| 786 | <listitem>
|
---|
| 787 | <para>The string to be inserted</para>
|
---|
| 788 | </listitem>
|
---|
| 789 | </varlistentry>
|
---|
| 790 | </variablelist>
|
---|
| 791 | </refparameter>
|
---|
| 792 | <refreturn>
|
---|
| 793 | <para>Returns string.</para>
|
---|
| 794 | </refreturn>
|
---|
| 795 | </doc:template>
|
---|
| 796 |
|
---|
| 797 | <xsl:template name="str:insert-at">
|
---|
| 798 | <xsl:param name="text"/>
|
---|
| 799 | <xsl:param name="position"/>
|
---|
| 800 | <xsl:param name="chars"/>
|
---|
| 801 |
|
---|
| 802 | <xsl:variable name="firstpart" select="substring($text, 0, $position)"/>
|
---|
| 803 | <xsl:variable name="secondpart" select="substring($text, $position, string-length($text))"/>
|
---|
| 804 |
|
---|
| 805 | <xsl:value-of select="concat($firstpart, $chars, $secondpart)"/>
|
---|
| 806 | </xsl:template>
|
---|
| 807 |
|
---|
| 808 |
|
---|
| 809 | <doc:template name="str:backward" xmlns="">
|
---|
| 810 | <refpurpose>String reversal</refpurpose>
|
---|
| 811 |
|
---|
| 812 | <refdescription>
|
---|
| 813 | <para>Reverse the content of a given string</para>
|
---|
| 814 | </refdescription>
|
---|
| 815 |
|
---|
| 816 | <refparameter>
|
---|
| 817 | <variablelist>
|
---|
| 818 | <varlistentry>
|
---|
| 819 | <term>text</term>
|
---|
| 820 | <listitem>
|
---|
| 821 | <para>The string to be reversed</para>
|
---|
| 822 | </listitem>
|
---|
| 823 | </varlistentry>
|
---|
| 824 | </variablelist>
|
---|
| 825 | </refparameter>
|
---|
| 826 |
|
---|
| 827 | <refreturn>
|
---|
| 828 | <para>Returns string.</para>
|
---|
| 829 | </refreturn>
|
---|
| 830 | </doc:template>
|
---|
| 831 |
|
---|
| 832 | <xsl:template name="str:backward">
|
---|
| 833 | <xsl:param name="text"/>
|
---|
| 834 | <xsl:variable name="mirror">
|
---|
| 835 | <xsl:call-template name="str:build-mirror">
|
---|
| 836 | <xsl:with-param name="text" select="$text"/>
|
---|
| 837 | <xsl:with-param name="position" select="string-length($text)"/>
|
---|
| 838 | </xsl:call-template>
|
---|
| 839 | </xsl:variable>
|
---|
| 840 | <xsl:value-of select="substring($mirror, string-length($text) + 1, string-length($text))"/>
|
---|
| 841 | </xsl:template>
|
---|
| 842 |
|
---|
| 843 | <xsl:template name="str:build-mirror">
|
---|
| 844 | <xsl:param name="text"/>
|
---|
| 845 | <xsl:param name="position"/>
|
---|
| 846 |
|
---|
| 847 | <xsl:choose>
|
---|
| 848 | <xsl:when test="$position > 0">
|
---|
| 849 | <xsl:call-template name="str:build-mirror">
|
---|
| 850 | <xsl:with-param name="text" select="concat($text, substring($text, $position, 1))"/>
|
---|
| 851 | <xsl:with-param name="position" select="$position - 1"/>
|
---|
| 852 | </xsl:call-template>
|
---|
| 853 | </xsl:when>
|
---|
| 854 | <xsl:otherwise>
|
---|
| 855 | <xsl:value-of select="$text"/>
|
---|
| 856 | </xsl:otherwise>
|
---|
| 857 | </xsl:choose>
|
---|
| 858 | </xsl:template>
|
---|
| 859 |
|
---|
| 860 | <doc:template name="str:justify" xmlns="">
|
---|
| 861 | <refpurpose>Format a string</refpurpose>
|
---|
| 862 |
|
---|
| 863 | <refdescription>
|
---|
| 864 | <para>Inserts newlines and spaces into a string to format it as a block of text.</para>
|
---|
| 865 | </refdescription>
|
---|
| 866 |
|
---|
| 867 | <refparameter>
|
---|
| 868 | <variablelist>
|
---|
| 869 | <varlistentry>
|
---|
| 870 | <term>text</term>
|
---|
| 871 | <listitem>
|
---|
| 872 | <para>String to be formatted.</para>
|
---|
| 873 | </listitem>
|
---|
| 874 | </varlistentry>
|
---|
| 875 | <varlistentry>
|
---|
| 876 | <term>max</term>
|
---|
| 877 | <listitem>
|
---|
| 878 | <para>Maximum line length.</para>
|
---|
| 879 | </listitem>
|
---|
| 880 | </varlistentry>
|
---|
| 881 | <varlistentry>
|
---|
| 882 | <term>indent</term>
|
---|
| 883 | <listitem>
|
---|
| 884 | <para>Number of spaces to insert at the beginning of each line.</para>
|
---|
| 885 | </listitem>
|
---|
| 886 | </varlistentry>
|
---|
| 887 | <varlistentry>
|
---|
| 888 | <term>justify</term>
|
---|
| 889 | <listitem>
|
---|
| 890 | <para>Justify left, right or both. Not currently implemented (fixed at "left").</para>
|
---|
| 891 | </listitem>
|
---|
| 892 | </varlistentry>
|
---|
| 893 | </variablelist>
|
---|
| 894 | </refparameter>
|
---|
| 895 |
|
---|
| 896 | <refreturn>
|
---|
| 897 | <para>Formatted block of text.</para>
|
---|
| 898 | </refreturn>
|
---|
| 899 | </doc:template>
|
---|
| 900 |
|
---|
| 901 | <xsl:template name='str:justify'>
|
---|
| 902 | <xsl:param name='text'/>
|
---|
| 903 | <xsl:param name='max' select='"80"'/>
|
---|
| 904 | <xsl:param name='indent' select='"0"'/>
|
---|
| 905 | <xsl:param name='justify' select='"left"'/>
|
---|
| 906 |
|
---|
| 907 | <xsl:choose>
|
---|
| 908 | <xsl:when test='string-length($text) = 0 or $max <= 0'/>
|
---|
| 909 |
|
---|
| 910 | <xsl:when test='string-length($text) > $max and contains($text, " ") and string-length(substring-before($text, " ")) > $max'>
|
---|
| 911 | <xsl:call-template name='str:generate-string'>
|
---|
| 912 | <xsl:with-param name='text' select='" "'/>
|
---|
| 913 | <xsl:with-param name='count' select='$indent'/>
|
---|
| 914 | </xsl:call-template>
|
---|
| 915 | <xsl:value-of select='substring-before($text, " ")'/>
|
---|
| 916 | <xsl:text>
|
---|
| 917 | </xsl:text>
|
---|
| 918 | <xsl:call-template name='str:justify'>
|
---|
| 919 | <xsl:with-param name='text' select='substring-after($text, " ")'/>
|
---|
| 920 | <xsl:with-param name='max' select='$max'/>
|
---|
| 921 | <xsl:with-param name='indent' select='$indent'/>
|
---|
| 922 | <xsl:with-param name='justify' select='$justify'/>
|
---|
| 923 | </xsl:call-template>
|
---|
| 924 | </xsl:when>
|
---|
| 925 |
|
---|
| 926 | <xsl:when test='string-length($text) > $max and contains($text, " ")'>
|
---|
| 927 | <xsl:variable name='first'>
|
---|
| 928 | <xsl:call-template name='str:substring-before-last'>
|
---|
| 929 | <xsl:with-param name='text' select='substring($text, 1, $max)'/>
|
---|
| 930 | <xsl:with-param name='chars' select='" "'/>
|
---|
| 931 | </xsl:call-template>
|
---|
| 932 | </xsl:variable>
|
---|
| 933 |
|
---|
| 934 | <xsl:call-template name='str:generate-string'>
|
---|
| 935 | <xsl:with-param name='text' select='" "'/>
|
---|
| 936 | <xsl:with-param name='count' select='$indent'/>
|
---|
| 937 | </xsl:call-template>
|
---|
| 938 | <xsl:value-of select='$first'/>
|
---|
| 939 | <xsl:text>
|
---|
| 940 | </xsl:text>
|
---|
| 941 | <xsl:call-template name='str:justify'>
|
---|
| 942 | <xsl:with-param name='text' select='substring($text, string-length($first) + 2)'/>
|
---|
| 943 | <xsl:with-param name='max' select='$max'/>
|
---|
| 944 | <xsl:with-param name='indent' select='$indent'/>
|
---|
| 945 | <xsl:with-param name='justify' select='$justify'/>
|
---|
| 946 | </xsl:call-template>
|
---|
| 947 | </xsl:when>
|
---|
| 948 |
|
---|
| 949 | <xsl:otherwise>
|
---|
| 950 | <xsl:call-template name='str:generate-string'>
|
---|
| 951 | <xsl:with-param name='text' select='" "'/>
|
---|
| 952 | <xsl:with-param name='count' select='$indent'/>
|
---|
| 953 | </xsl:call-template>
|
---|
| 954 | <xsl:value-of select='$text'/>
|
---|
| 955 | </xsl:otherwise>
|
---|
| 956 | </xsl:choose>
|
---|
| 957 | </xsl:template>
|
---|
| 958 |
|
---|
| 959 | <doc:template name="str:character-first" xmlns="">
|
---|
| 960 | <refpurpose>Find first occurring character in a string</refpurpose>
|
---|
| 961 |
|
---|
| 962 | <refdescription>
|
---|
| 963 | <para>Finds which of the given characters occurs first in a string.</para>
|
---|
| 964 | </refdescription>
|
---|
| 965 |
|
---|
| 966 | <refparameter>
|
---|
| 967 | <variablelist>
|
---|
| 968 | <varlistentry>
|
---|
| 969 | <term>text</term>
|
---|
| 970 | <listitem>
|
---|
| 971 | <para>The source string.</para>
|
---|
| 972 | </listitem>
|
---|
| 973 | </varlistentry>
|
---|
| 974 | <varlistentry>
|
---|
| 975 | <term>chars</term>
|
---|
| 976 | <listitem>
|
---|
| 977 | <para>The characters to search for.</para>
|
---|
| 978 | </listitem>
|
---|
| 979 | </varlistentry>
|
---|
| 980 | </variablelist>
|
---|
| 981 | </refparameter>
|
---|
| 982 | </doc:template>
|
---|
| 983 |
|
---|
| 984 | <xsl:template name="str:character-first">
|
---|
| 985 | <xsl:param name="text"/>
|
---|
| 986 | <xsl:param name="chars"/>
|
---|
| 987 |
|
---|
| 988 | <xsl:choose>
|
---|
| 989 | <xsl:when test="string-length($text) = 0 or string-length($chars) = 0"/>
|
---|
| 990 |
|
---|
| 991 | <xsl:when test="contains($text, substring($chars, 1, 1))">
|
---|
| 992 | <xsl:variable name="next-character">
|
---|
| 993 | <xsl:call-template name="str:character-first">
|
---|
| 994 | <xsl:with-param name="text" select="$text"/>
|
---|
| 995 | <xsl:with-param name="chars" select="substring($chars, 2)"/>
|
---|
| 996 | </xsl:call-template>
|
---|
| 997 | </xsl:variable>
|
---|
| 998 |
|
---|
| 999 | <xsl:choose>
|
---|
| 1000 | <xsl:when test="string-length($next-character)">
|
---|
| 1001 | <xsl:variable name="first-character-position" select="string-length(substring-before($text, substring($chars, 1, 1)))"/>
|
---|
| 1002 | <xsl:variable name="next-character-position" select="string-length(substring-before($text, $next-character))"/>
|
---|
| 1003 |
|
---|
| 1004 | <xsl:choose>
|
---|
| 1005 | <xsl:when test="$first-character-position < $next-character-position">
|
---|
| 1006 | <xsl:value-of select="substring($chars, 1, 1)"/>
|
---|
| 1007 | </xsl:when>
|
---|
| 1008 | <xsl:otherwise>
|
---|
| 1009 | <xsl:value-of select="$next-character"/>
|
---|
| 1010 | </xsl:otherwise>
|
---|
| 1011 | </xsl:choose>
|
---|
| 1012 | </xsl:when>
|
---|
| 1013 | <xsl:otherwise>
|
---|
| 1014 | <xsl:value-of select="substring($chars, 1, 1)"/>
|
---|
| 1015 | </xsl:otherwise>
|
---|
| 1016 | </xsl:choose>
|
---|
| 1017 | </xsl:when>
|
---|
| 1018 | <xsl:otherwise>
|
---|
| 1019 | <xsl:call-template name="str:character-first">
|
---|
| 1020 | <xsl:with-param name="text" select="$text"/>
|
---|
| 1021 | <xsl:with-param name="chars" select="substring($chars, 2)"/>
|
---|
| 1022 | </xsl:call-template>
|
---|
| 1023 | </xsl:otherwise>
|
---|
| 1024 | </xsl:choose>
|
---|
| 1025 | </xsl:template>
|
---|
| 1026 |
|
---|
| 1027 | <doc:template name="str:string-match" xmlns="">
|
---|
| 1028 | <refpurpose>Match A String To A Pattern</refpurpose>
|
---|
| 1029 |
|
---|
| 1030 | <refdescription>
|
---|
| 1031 | <para>Performs globbing-style pattern matching on a string.</para>
|
---|
| 1032 | </refdescription>
|
---|
| 1033 |
|
---|
| 1034 | <example>
|
---|
| 1035 | <title>Match Pattern</title>
|
---|
| 1036 | <programlisting><![CDATA[
|
---|
| 1037 | <xsl:call-template name="str:string-match">
|
---|
| 1038 | <xsl:with-param name="text" select="$mytext"/>
|
---|
| 1039 | <xsl:with-param name="pattern" select="'abc*def?g'"/>
|
---|
| 1040 | </xsl:call-template>
|
---|
| 1041 | ]]></programlisting>
|
---|
| 1042 | </example>
|
---|
| 1043 |
|
---|
| 1044 | <refparameter>
|
---|
| 1045 | <variablelist>
|
---|
| 1046 | <varlistentry>
|
---|
| 1047 | <term>text</term>
|
---|
| 1048 | <listitem>
|
---|
| 1049 | <para>The source string.</para>
|
---|
| 1050 | </listitem>
|
---|
| 1051 | </varlistentry>
|
---|
| 1052 | <varlistentry>
|
---|
| 1053 | <term>pattern</term>
|
---|
| 1054 | <listitem>
|
---|
| 1055 | <para>The pattern to match against. Certain characters have special meaning:</para>
|
---|
| 1056 | <variablelist>
|
---|
| 1057 | <varlistentry>
|
---|
| 1058 | <term>*</term>
|
---|
| 1059 | <listitem>
|
---|
| 1060 | <para>Matches zero or more characters.</para>
|
---|
| 1061 | </listitem>
|
---|
| 1062 | </varlistentry>
|
---|
| 1063 | <varlistentry>
|
---|
| 1064 | <term>?</term>
|
---|
| 1065 | <listitem>
|
---|
| 1066 | <para>Matches a single character.</para>
|
---|
| 1067 | </listitem>
|
---|
| 1068 | </varlistentry>
|
---|
| 1069 | <varlistentry>
|
---|
| 1070 | <term>\</term>
|
---|
| 1071 | <listitem>
|
---|
| 1072 | <para>Character escape. The next character is taken as a literal character.</para>
|
---|
| 1073 | </listitem>
|
---|
| 1074 | </varlistentry>
|
---|
| 1075 | </variablelist>
|
---|
| 1076 | </listitem>
|
---|
| 1077 | </varlistentry>
|
---|
| 1078 | </variablelist>
|
---|
| 1079 | </refparameter>
|
---|
| 1080 |
|
---|
| 1081 | <refreturn>
|
---|
| 1082 | <para>Returns "1" if the string matches the pattern, "0" otherwise.</para>
|
---|
| 1083 | </refreturn>
|
---|
| 1084 | </doc:template>
|
---|
| 1085 |
|
---|
| 1086 | <xsl:template name="str:string-match">
|
---|
| 1087 | <xsl:param name="text"/>
|
---|
| 1088 | <xsl:param name="pattern"/>
|
---|
| 1089 |
|
---|
| 1090 | <xsl:choose>
|
---|
| 1091 | <xsl:when test="$pattern = '*'">
|
---|
| 1092 | <!-- Special case: always matches -->
|
---|
| 1093 | <xsl:text>1</xsl:text>
|
---|
| 1094 | </xsl:when>
|
---|
| 1095 | <xsl:when test="string-length($text) = 0 and string-length($pattern) = 0">
|
---|
| 1096 | <xsl:text>1</xsl:text>
|
---|
| 1097 | </xsl:when>
|
---|
| 1098 | <xsl:when test="string-length($text) = 0 or string-length($pattern) = 0">
|
---|
| 1099 | <xsl:text>0</xsl:text>
|
---|
| 1100 | </xsl:when>
|
---|
| 1101 | <xsl:otherwise>
|
---|
| 1102 | <xsl:variable name='before-special'>
|
---|
| 1103 | <xsl:call-template name='str:substring-before-first'>
|
---|
| 1104 | <xsl:with-param name='text' select='$pattern'/>
|
---|
| 1105 | <xsl:with-param name='chars' select='"*?\"'/>
|
---|
| 1106 | </xsl:call-template>
|
---|
| 1107 | </xsl:variable>
|
---|
| 1108 | <xsl:variable name='special'>
|
---|
| 1109 | <xsl:call-template name='str:character-first'>
|
---|
| 1110 | <xsl:with-param name='text' select='$pattern'/>
|
---|
| 1111 | <xsl:with-param name='chars' select='"*?\"'/>
|
---|
| 1112 | </xsl:call-template>
|
---|
| 1113 | </xsl:variable>
|
---|
| 1114 |
|
---|
| 1115 | <xsl:variable name='new-text' select='substring($text, string-length($before-special) + 1)'/>
|
---|
| 1116 | <xsl:variable name='new-pattern' select='substring($pattern, string-length($before-special) + 1)'/>
|
---|
| 1117 |
|
---|
| 1118 | <xsl:choose>
|
---|
| 1119 | <xsl:when test="not(starts-with($text, $before-special))">
|
---|
| 1120 | <!-- Verbatim characters don't match -->
|
---|
| 1121 | <xsl:text>0</xsl:text>
|
---|
| 1122 | </xsl:when>
|
---|
| 1123 |
|
---|
| 1124 | <xsl:when test="$special = '*' and string-length($new-pattern) = 1">
|
---|
| 1125 | <xsl:text>1</xsl:text>
|
---|
| 1126 | </xsl:when>
|
---|
| 1127 | <xsl:when test="$special = '*'">
|
---|
| 1128 | <xsl:call-template name='str:match-postfix'>
|
---|
| 1129 | <xsl:with-param name='text' select='$new-text'/>
|
---|
| 1130 | <xsl:with-param name='pattern' select='substring($new-pattern, 2)'/>
|
---|
| 1131 | </xsl:call-template>
|
---|
| 1132 | </xsl:when>
|
---|
| 1133 |
|
---|
| 1134 | <xsl:when test="$special = '?'">
|
---|
| 1135 | <xsl:call-template name="str:string-match">
|
---|
| 1136 | <xsl:with-param name='text' select='substring($new-text, 2)'/>
|
---|
| 1137 | <xsl:with-param name='pattern' select='substring($new-pattern, 2)'/>
|
---|
| 1138 | </xsl:call-template>
|
---|
| 1139 | </xsl:when>
|
---|
| 1140 |
|
---|
| 1141 | <xsl:when test="$special = '\' and substring($new-text, 1, 1) = substring($new-pattern, 2, 1)">
|
---|
| 1142 | <xsl:call-template name="str:string-match">
|
---|
| 1143 | <xsl:with-param name='text' select='substring($new-text, 2)'/>
|
---|
| 1144 | <xsl:with-param name='pattern' select='substring($new-pattern, 3)'/>
|
---|
| 1145 | </xsl:call-template>
|
---|
| 1146 | </xsl:when>
|
---|
| 1147 | <xsl:when test="$special = '\' and substring($new-text, 1, 1) != substring($new-pattern, 2, 1)">
|
---|
| 1148 | <xsl:text>0</xsl:text>
|
---|
| 1149 | </xsl:when>
|
---|
| 1150 |
|
---|
| 1151 | <xsl:otherwise>
|
---|
| 1152 | <!-- There were no special characters in the pattern -->
|
---|
| 1153 | <xsl:choose>
|
---|
| 1154 | <xsl:when test='$text = $pattern'>
|
---|
| 1155 | <xsl:text>1</xsl:text>
|
---|
| 1156 | </xsl:when>
|
---|
| 1157 | <xsl:otherwise>
|
---|
| 1158 | <xsl:text>0</xsl:text>
|
---|
| 1159 | </xsl:otherwise>
|
---|
| 1160 | </xsl:choose>
|
---|
| 1161 | </xsl:otherwise>
|
---|
| 1162 | </xsl:choose>
|
---|
| 1163 | </xsl:otherwise>
|
---|
| 1164 | </xsl:choose>
|
---|
| 1165 | </xsl:template>
|
---|
| 1166 |
|
---|
| 1167 | <xsl:template name="str:match-postfix">
|
---|
| 1168 | <xsl:param name="text"/>
|
---|
| 1169 | <xsl:param name="pattern"/>
|
---|
| 1170 |
|
---|
| 1171 | <xsl:variable name='result'>
|
---|
| 1172 | <xsl:call-template name='str:string-match'>
|
---|
| 1173 | <xsl:with-param name='text' select='$text'/>
|
---|
| 1174 | <xsl:with-param name='pattern' select='$pattern'/>
|
---|
| 1175 | </xsl:call-template>
|
---|
| 1176 | </xsl:variable>
|
---|
| 1177 |
|
---|
| 1178 | <xsl:choose>
|
---|
| 1179 | <xsl:when test='$result = "1"'>
|
---|
| 1180 | <xsl:value-of select='$result'/>
|
---|
| 1181 | </xsl:when>
|
---|
| 1182 | <xsl:when test='string-length($text) = 0'>
|
---|
| 1183 | <xsl:text>0</xsl:text>
|
---|
| 1184 | </xsl:when>
|
---|
| 1185 | <xsl:otherwise>
|
---|
| 1186 | <xsl:call-template name='str:match-postfix'>
|
---|
| 1187 | <xsl:with-param name='text' select='substring($text, 2)'/>
|
---|
| 1188 | <xsl:with-param name='pattern' select='$pattern'/>
|
---|
| 1189 | </xsl:call-template>
|
---|
| 1190 | </xsl:otherwise>
|
---|
| 1191 | </xsl:choose>
|
---|
| 1192 |
|
---|
| 1193 | </xsl:template>
|
---|
| 1194 |
|
---|
| 1195 | <doc:template name="str:generate-string" xmlns="">
|
---|
| 1196 | <refpurpose>Create A Repeating Sequence of Characters</refpurpose>
|
---|
| 1197 |
|
---|
| 1198 | <refdescription>
|
---|
| 1199 | <para>Repeats a string a given number of times.</para>
|
---|
| 1200 | </refdescription>
|
---|
| 1201 |
|
---|
| 1202 | <refparameter>
|
---|
| 1203 | <variablelist>
|
---|
| 1204 | <varlistentry>
|
---|
| 1205 | <term>text</term>
|
---|
| 1206 | <listitem>
|
---|
| 1207 | <para>The string to repeat.</para>
|
---|
| 1208 | </listitem>
|
---|
| 1209 | </varlistentry>
|
---|
| 1210 | <varlistentry>
|
---|
| 1211 | <term>count</term>
|
---|
| 1212 | <listitem>
|
---|
| 1213 | <para>The number of times to repeat the string.</para>
|
---|
| 1214 | </listitem>
|
---|
| 1215 | </varlistentry>
|
---|
| 1216 | </variablelist>
|
---|
| 1217 | </refparameter>
|
---|
| 1218 | </doc:template>
|
---|
| 1219 |
|
---|
| 1220 | <xsl:template name="str:generate-string">
|
---|
| 1221 | <xsl:param name="text"/>
|
---|
| 1222 | <xsl:param name="count"/>
|
---|
| 1223 |
|
---|
| 1224 | <xsl:choose>
|
---|
| 1225 | <xsl:when test="string-length($text) = 0 or $count <= 0"/>
|
---|
| 1226 | <xsl:otherwise>
|
---|
| 1227 | <xsl:value-of select="$text"/>
|
---|
| 1228 | <xsl:call-template name="str:generate-string">
|
---|
| 1229 | <xsl:with-param name="text" select="$text"/>
|
---|
| 1230 | <xsl:with-param name="count" select="$count - 1"/>
|
---|
| 1231 | </xsl:call-template>
|
---|
| 1232 | </xsl:otherwise>
|
---|
| 1233 | </xsl:choose>
|
---|
| 1234 | </xsl:template>
|
---|
| 1235 |
|
---|
| 1236 | </xsl:stylesheet>
|
---|
| 1237 |
|
---|