Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

string.xsl 49KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0"
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
  5. xmlns:str="http://xsltsl.org/string"
  6. extension-element-prefixes="doc str">
  7. <doc:reference xmlns="">
  8. <referenceinfo>
  9. <releaseinfo role="meta">
  10. $Id: string.xsl,v 1.13 2004/10/08 06:37:25 balls Exp $
  11. </releaseinfo>
  12. <author>
  13. <surname>Ball</surname>
  14. <firstname>Steve</firstname>
  15. </author>
  16. <copyright>
  17. <year>2002</year>
  18. <year>2001</year>
  19. <holder>Steve Ball</holder>
  20. </copyright>
  21. </referenceinfo>
  22. <title>String Processing</title>
  23. <partintro>
  24. <section>
  25. <title>Introduction</title>
  26. <para>This module provides templates for manipulating strings.</para>
  27. </section>
  28. </partintro>
  29. </doc:reference>
  30. <!-- Common string constants and datasets as XSL variables -->
  31. <!-- str:lower and str:upper contain pairs of lower and upper case
  32. characters. Below insanely long strings should contain the
  33. official lower/uppercase pairs, making this stylesheet working
  34. for every language on earth. Hopefully. -->
  35. <!-- These values are not enough, however. There are some
  36. exceptions, dealt with below. -->
  37. <xsl:variable name="xsltsl-str-lower" select="'&#x0061;&#x0062;&#x0063;&#x0064;&#x0065;&#x0066;&#x0067;&#x0068;&#x0069;&#x006A;&#x006B;&#x006C;&#x006D;&#x006E;&#x006F;&#x0070;&#x0071;&#x0072;&#x0073;&#x0074;&#x0075;&#x0076;&#x0077;&#x0078;&#x0079;&#x007A;&#x00B5;&#x00E0;&#x00E1;&#x00E2;&#x00E3;&#x00E4;&#x00E5;&#x00E6;&#x00E7;&#x00E8;&#x00E9;&#x00EA;&#x00EB;&#x00EC;&#x00ED;&#x00EE;&#x00EF;&#x00F0;&#x00F1;&#x00F2;&#x00F3;&#x00F4;&#x00F5;&#x00F6;&#x00F8;&#x00F9;&#x00FA;&#x00FB;&#x00FC;&#x00FD;&#x00FE;&#x00FF;&#x0101;&#x0103;&#x0105;&#x0107;&#x0109;&#x010B;&#x010D;&#x010F;&#x0111;&#x0113;&#x0115;&#x0117;&#x0119;&#x011B;&#x011D;&#x011F;&#x0121;&#x0123;&#x0125;&#x0127;&#x0129;&#x012B;&#x012D;&#x012F;&#x0131;&#x0133;&#x0135;&#x0137;&#x013A;&#x013C;&#x013E;&#x0140;&#x0142;&#x0144;&#x0146;&#x0148;&#x014B;&#x014D;&#x014F;&#x0151;&#x0153;&#x0155;&#x0157;&#x0159;&#x015B;&#x015D;&#x015F;&#x0161;&#x0163;&#x0165;&#x0167;&#x0169;&#x016B;&#x016D;&#x016F;&#x0171;&#x0173;&#x0175;&#x0177;&#x017A;&#x017C;&#x017E;&#x017F;&#x0183;&#x0185;&#x0188;&#x018C;&#x0192;&#x0195;&#x0199;&#x01A1;&#x01A3;&#x01A5;&#x01A8;&#x01AD;&#x01B0;&#x01B4;&#x01B6;&#x01B9;&#x01BD;&#x01BF;&#x01C5;&#x01C6;&#x01C8;&#x01C9;&#x01CB;&#x01CC;&#x01CE;&#x01D0;&#x01D2;&#x01D4;&#x01D6;&#x01D8;&#x01DA;&#x01DC;&#x01DD;&#x01DF;&#x01E1;&#x01E3;&#x01E5;&#x01E7;&#x01E9;&#x01EB;&#x01ED;&#x01EF;&#x01F2;&#x01F3;&#x01F5;&#x01F9;&#x01FB;&#x01FD;&#x01FF;&#x0201;&#x0203;&#x0205;&#x0207;&#x0209;&#x020B;&#x020D;&#x020F;&#x0211;&#x0213;&#x0215;&#x0217;&#x0219;&#x021B;&#x021D;&#x021F;&#x0223;&#x0225;&#x0227;&#x0229;&#x022B;&#x022D;&#x022F;&#x0231;&#x0233;&#x0253;&#x0254;&#x0256;&#x0257;&#x0259;&#x025B;&#x0260;&#x0263;&#x0268;&#x0269;&#x026F;&#x0272;&#x0275;&#x0280;&#x0283;&#x0288;&#x028A;&#x028B;&#x0292;&#x0345;&#x03AC;&#x03AD;&#x03AE;&#x03AF;&#x03B1;&#x03B2;&#x03B3;&#x03B4;&#x03B5;&#x03B6;&#x03B7;&#x03B8;&#x03B9;&#x03BA;&#x03BB;&#x03BC;&#x03BD;&#x03BE;&#x03BF;&#x03C0;&#x03C1;&#x03C2;&#x03C3;&#x03C4;&#x03C5;&#x03C6;&#x03C7;&#x03C8;&#x03C9;&#x03CA;&#x03CB;&#x03CC;&#x03CD;&#x03CE;&#x03D0;&#x03D1;&#x03D5;&#x03D6;&#x03DB;&#x03DD;&#x03DF;&#x03E1;&#x03E3;&#x03E5;&#x03E7;&#x03E9;&#x03EB;&#x03ED;&#x03EF;&#x03F0;&#x03F1;&#x03F2;&#x03F5;&#x0430;&#x0431;&#x0432;&#x0433;&#x0434;&#x0435;&#x0436;&#x0437;&#x0438;&#x0439;&#x043A;&#x043B;&#x043C;&#x043D;&#x043E;&#x043F;&#x0440;&#x0441;&#x0442;&#x0443;&#x0444;&#x0445;&#x0446;&#x0447;&#x0448;&#x0449;&#x044A;&#x044B;&#x044C;&#x044D;&#x044E;&#x044F;&#x0450;&#x0451;&#x0452;&#x0453;&#x0454;&#x0455;&#x0456;&#x0457;&#x0458;&#x0459;&#x045A;&#x045B;&#x045C;&#x045D;&#x045E;&#x045F;&#x0461;&#x0463;&#x0465;&#x0467;&#x0469;&#x046B;&#x046D;&#x046F;&#x0471;&#x0473;&#x0475;&#x0477;&#x0479;&#x047B;&#x047D;&#x047F;&#x0481;&#x048D;&#x048F;&#x0491;&#x0493;&#x0495;&#x0497;&#x0499;&#x049B;&#x049D;&#x049F;&#x04A1;&#x04A3;&#x04A5;&#x04A7;&#x04A9;&#x04AB;&#x04AD;&#x04AF;&#x04B1;&#x04B3;&#x04B5;&#x04B7;&#x04B9;&#x04BB;&#x04BD;&#x04BF;&#x04C2;&#x04C4;&#x04C8;&#x04CC;&#x04D1;&#x04D3;&#x04D5;&#x04D7;&#x04D9;&#x04DB;&#x04DD;&#x04DF;&#x04E1;&#x04E3;&#x04E5;&#x04E7;&#x04E9;&#x04EB;&#x04ED;&#x04EF;&#x04F1;&#x04F3;&#x04F5;&#x04F9;&#x0561;&#x0562;&#x0563;&#x0564;&#x0565;&#x0566;&#x0567;&#x0568;&#x0569;&#x056A;&#x056B;&#x056C;&#x056D;&#x056E;&#x056F;&#x0570;&#x0571;&#x0572;&#x0573;&#x0574;&#x0575;&#x0576;&#x0577;&#x0578;&#x0579;&#x057A;&#x057B;&#x057C;&#x057D;&#x057E;&#x057F;&#x0580;&#x0581;&#x0582;&#x0583;&#x0584;&#x0585;&#x0586;&#x1E01;&#x1E03;&#x1E05;&#x1E07;&#x1E09;&#x1E0B;&#x1E0D;&#x1E0F;&#x1E11;&#x1E13;&#x1E15;&#x1E17;&#x1E19;&#x1E1B;&#x1E1D;&#x1E1F;&#x1E21;&#x1E23;&#x1E25;&#x1E27;&#x1E29;&#x1E2B;&#x1E2D;&#x1E2F;&#x1E31;&#x1E33;&#x1E35;&#x1E37;&#x1E39;&#x1E3B;&#x1E3D;&#x1E3F;&#x1E41;&#x1E43;&#x1E45;&#x1E47;&#x1E49;&#x1E4B;&#x1E4D;&#x1E4F;&#x1E51;&#x1E53;&#x1E55;&#x1E57;&#x1E59;&#x1E5B;&#x1E5D;&#x1E5F;&#x1E61;&#x1E63;&#x1E65;&#x1E67;&#x1E69;&#x1E6B;&#x1E6D;&#x1E6F;&#x1E71;&#x1E73;&#x1E75;&#x1E77;&#x1E79;&#x1E7B;&#x1E7D;&#x1E7F;&#x1E81;&#x1E83;&#x1E85;&#x1E87;&#x1E89;&#x1E8B;&#x1E8D;&#x1E8F;&#x1E91;&#x1E93;&#x1E95;&#x1E9B;&#x1EA1;&#x1EA3;&#x1EA5;&#x1EA7;&#x1EA9;&#x1EAB;&#x1EAD;&#x1EAF;&#x1EB1;&#x1EB3;&#x1EB5;&#x1EB7;&#x1EB9;&#x1EBB;&#x1EBD;&#x1EBF;&#x1EC1;&#x1EC3;&#x1EC5;&#x1EC7;&#x1EC9;&#x1ECB;&#x1ECD;&#x1ECF;&#x1ED1;&#x1ED3;&#x1ED5;&#x1ED7;&#x1ED9;&#x1EDB;&#x1EDD;&#x1EDF;&#x1EE1;&#x1EE3;&#x1EE5;&#x1EE7;&#x1EE9;&#x1EEB;&#x1EED;&#x1EEF;&#x1EF1;&#x1EF3;&#x1EF5;&#x1EF7;&#x1EF9;&#x1F00;&#x1F01;&#x1F02;&#x1F03;&#x1F04;&#x1F05;&#x1F06;&#x1F07;&#x1F10;&#x1F11;&#x1F12;&#x1F13;&#x1F14;&#x1F15;&#x1F20;&#x1F21;&#x1F22;&#x1F23;&#x1F24;&#x1F25;&#x1F26;&#x1F27;&#x1F30;&#x1F31;&#x1F32;&#x1F33;&#x1F34;&#x1F35;&#x1F36;&#x1F37;&#x1F40;&#x1F41;&#x1F42;&#x1F43;&#x1F44;&#x1F45;&#x1F51;&#x1F53;&#x1F55;&#x1F57;&#x1F60;&#x1F61;&#x1F62;&#x1F63;&#x1F64;&#x1F65;&#x1F66;&#x1F67;&#x1F70;&#x1F71;&#x1F72;&#x1F73;&#x1F74;&#x1F75;&#x1F76;&#x1F77;&#x1F78;&#x1F79;&#x1F7A;&#x1F7B;&#x1F7C;&#x1F7D;&#x1F80;&#x1F81;&#x1F82;&#x1F83;&#x1F84;&#x1F85;&#x1F86;&#x1F87;&#x1F90;&#x1F91;&#x1F92;&#x1F93;&#x1F94;&#x1F95;&#x1F96;&#x1F97;&#x1FA0;&#x1FA1;&#x1FA2;&#x1FA3;&#x1FA4;&#x1FA5;&#x1FA6;&#x1FA7;&#x1FB0;&#x1FB1;&#x1FB3;&#x1FBE;&#x1FC3;&#x1FD0;&#x1FD1;&#x1FE0;&#x1FE1;&#x1FE5;&#x1FF3;&#x2170;&#x2171;&#x2172;&#x2173;&#x2174;&#x2175;&#x2176;&#x2177;&#x2178;&#x2179;&#x217A;&#x217B;&#x217C;&#x217D;&#x217E;&#x217F;&#x24D0;&#x24D1;&#x24D2;&#x24D3;&#x24D4;&#x24D5;&#x24D6;&#x24D7;&#x24D8;&#x24D9;&#x24DA;&#x24DB;&#x24DC;&#x24DD;&#x24DE;&#x24DF;&#x24E0;&#x24E1;&#x24E2;&#x24E3;&#x24E4;&#x24E5;&#x24E6;&#x24E7;&#x24E8;&#x24E9;&#xFF41;&#xFF42;&#xFF43;&#xFF44;&#xFF45;&#xFF46;&#xFF47;&#xFF48;&#xFF49;&#xFF4A;&#xFF4B;&#xFF4C;&#xFF4D;&#xFF4E;&#xFF4F;&#xFF50;&#xFF51;&#xFF52;&#xFF53;&#xFF54;&#xFF55;&#xFF56;&#xFF57;&#xFF58;&#xFF59;&#xFF5A;&#x10428;&#x10429;&#x1042A;&#x1042B;&#x1042C;&#x1042D;&#x1042E;&#x1042F;&#x10430;&#x10431;&#x10432;&#x10433;&#x10434;&#x10435;&#x10436;&#x10437;&#x10438;&#x10439;&#x1043A;&#x1043B;&#x1043C;&#x1043D;&#x1043E;&#x1043F;&#x10440;&#x10441;&#x10442;&#x10443;&#x10444;&#x10445;&#x10446;&#x10447;&#x10448;&#x10449;&#x1044A;&#x1044B;&#x1044C;&#x1044D;'"/>
  38. <xsl:variable name="xsltsl-str-upper" select="'&#x0041;&#x0042;&#x0043;&#x0044;&#x0045;&#x0046;&#x0047;&#x0048;&#x0049;&#x004A;&#x004B;&#x004C;&#x004D;&#x004E;&#x004F;&#x0050;&#x0051;&#x0052;&#x0053;&#x0054;&#x0055;&#x0056;&#x0057;&#x0058;&#x0059;&#x005A;&#x039C;&#x00C0;&#x00C1;&#x00C2;&#x00C3;&#x00C4;&#x00C5;&#x00C6;&#x00C7;&#x00C8;&#x00C9;&#x00CA;&#x00CB;&#x00CC;&#x00CD;&#x00CE;&#x00CF;&#x00D0;&#x00D1;&#x00D2;&#x00D3;&#x00D4;&#x00D5;&#x00D6;&#x00D8;&#x00D9;&#x00DA;&#x00DB;&#x00DC;&#x00DD;&#x00DE;&#x0178;&#x0100;&#x0102;&#x0104;&#x0106;&#x0108;&#x010A;&#x010C;&#x010E;&#x0110;&#x0112;&#x0114;&#x0116;&#x0118;&#x011A;&#x011C;&#x011E;&#x0120;&#x0122;&#x0124;&#x0126;&#x0128;&#x012A;&#x012C;&#x012E;&#x0049;&#x0132;&#x0134;&#x0136;&#x0139;&#x013B;&#x013D;&#x013F;&#x0141;&#x0143;&#x0145;&#x0147;&#x014A;&#x014C;&#x014E;&#x0150;&#x0152;&#x0154;&#x0156;&#x0158;&#x015A;&#x015C;&#x015E;&#x0160;&#x0162;&#x0164;&#x0166;&#x0168;&#x016A;&#x016C;&#x016E;&#x0170;&#x0172;&#x0174;&#x0176;&#x0179;&#x017B;&#x017D;&#x0053;&#x0182;&#x0184;&#x0187;&#x018B;&#x0191;&#x01F6;&#x0198;&#x01A0;&#x01A2;&#x01A4;&#x01A7;&#x01AC;&#x01AF;&#x01B3;&#x01B5;&#x01B8;&#x01BC;&#x01F7;&#x01C4;&#x01C4;&#x01C7;&#x01C7;&#x01CA;&#x01CA;&#x01CD;&#x01CF;&#x01D1;&#x01D3;&#x01D5;&#x01D7;&#x01D9;&#x01DB;&#x018E;&#x01DE;&#x01E0;&#x01E2;&#x01E4;&#x01E6;&#x01E8;&#x01EA;&#x01EC;&#x01EE;&#x01F1;&#x01F1;&#x01F4;&#x01F8;&#x01FA;&#x01FC;&#x01FE;&#x0200;&#x0202;&#x0204;&#x0206;&#x0208;&#x020A;&#x020C;&#x020E;&#x0210;&#x0212;&#x0214;&#x0216;&#x0218;&#x021A;&#x021C;&#x021E;&#x0222;&#x0224;&#x0226;&#x0228;&#x022A;&#x022C;&#x022E;&#x0230;&#x0232;&#x0181;&#x0186;&#x0189;&#x018A;&#x018F;&#x0190;&#x0193;&#x0194;&#x0197;&#x0196;&#x019C;&#x019D;&#x019F;&#x01A6;&#x01A9;&#x01AE;&#x01B1;&#x01B2;&#x01B7;&#x0399;&#x0386;&#x0388;&#x0389;&#x038A;&#x0391;&#x0392;&#x0393;&#x0394;&#x0395;&#x0396;&#x0397;&#x0398;&#x0399;&#x039A;&#x039B;&#x039C;&#x039D;&#x039E;&#x039F;&#x03A0;&#x03A1;&#x03A3;&#x03A3;&#x03A4;&#x03A5;&#x03A6;&#x03A7;&#x03A8;&#x03A9;&#x03AA;&#x03AB;&#x038C;&#x038E;&#x038F;&#x0392;&#x0398;&#x03A6;&#x03A0;&#x03DA;&#x03DC;&#x03DE;&#x03E0;&#x03E2;&#x03E4;&#x03E6;&#x03E8;&#x03EA;&#x03EC;&#x03EE;&#x039A;&#x03A1;&#x03A3;&#x0395;&#x0410;&#x0411;&#x0412;&#x0413;&#x0414;&#x0415;&#x0416;&#x0417;&#x0418;&#x0419;&#x041A;&#x041B;&#x041C;&#x041D;&#x041E;&#x041F;&#x0420;&#x0421;&#x0422;&#x0423;&#x0424;&#x0425;&#x0426;&#x0427;&#x0428;&#x0429;&#x042A;&#x042B;&#x042C;&#x042D;&#x042E;&#x042F;&#x0400;&#x0401;&#x0402;&#x0403;&#x0404;&#x0405;&#x0406;&#x0407;&#x0408;&#x0409;&#x040A;&#x040B;&#x040C;&#x040D;&#x040E;&#x040F;&#x0460;&#x0462;&#x0464;&#x0466;&#x0468;&#x046A;&#x046C;&#x046E;&#x0470;&#x0472;&#x0474;&#x0476;&#x0478;&#x047A;&#x047C;&#x047E;&#x0480;&#x048C;&#x048E;&#x0490;&#x0492;&#x0494;&#x0496;&#x0498;&#x049A;&#x049C;&#x049E;&#x04A0;&#x04A2;&#x04A4;&#x04A6;&#x04A8;&#x04AA;&#x04AC;&#x04AE;&#x04B0;&#x04B2;&#x04B4;&#x04B6;&#x04B8;&#x04BA;&#x04BC;&#x04BE;&#x04C1;&#x04C3;&#x04C7;&#x04CB;&#x04D0;&#x04D2;&#x04D4;&#x04D6;&#x04D8;&#x04DA;&#x04DC;&#x04DE;&#x04E0;&#x04E2;&#x04E4;&#x04E6;&#x04E8;&#x04EA;&#x04EC;&#x04EE;&#x04F0;&#x04F2;&#x04F4;&#x04F8;&#x0531;&#x0532;&#x0533;&#x0534;&#x0535;&#x0536;&#x0537;&#x0538;&#x0539;&#x053A;&#x053B;&#x053C;&#x053D;&#x053E;&#x053F;&#x0540;&#x0541;&#x0542;&#x0543;&#x0544;&#x0545;&#x0546;&#x0547;&#x0548;&#x0549;&#x054A;&#x054B;&#x054C;&#x054D;&#x054E;&#x054F;&#x0550;&#x0551;&#x0552;&#x0553;&#x0554;&#x0555;&#x0556;&#x1E00;&#x1E02;&#x1E04;&#x1E06;&#x1E08;&#x1E0A;&#x1E0C;&#x1E0E;&#x1E10;&#x1E12;&#x1E14;&#x1E16;&#x1E18;&#x1E1A;&#x1E1C;&#x1E1E;&#x1E20;&#x1E22;&#x1E24;&#x1E26;&#x1E28;&#x1E2A;&#x1E2C;&#x1E2E;&#x1E30;&#x1E32;&#x1E34;&#x1E36;&#x1E38;&#x1E3A;&#x1E3C;&#x1E3E;&#x1E40;&#x1E42;&#x1E44;&#x1E46;&#x1E48;&#x1E4A;&#x1E4C;&#x1E4E;&#x1E50;&#x1E52;&#x1E54;&#x1E56;&#x1E58;&#x1E5A;&#x1E5C;&#x1E5E;&#x1E60;&#x1E62;&#x1E64;&#x1E66;&#x1E68;&#x1E6A;&#x1E6C;&#x1E6E;&#x1E70;&#x1E72;&#x1E74;&#x1E76;&#x1E78;&#x1E7A;&#x1E7C;&#x1E7E;&#x1E80;&#x1E82;&#x1E84;&#x1E86;&#x1E88;&#x1E8A;&#x1E8C;&#x1E8E;&#x1E90;&#x1E92;&#x1E94;&#x1E60;&#x1EA0;&#x1EA2;&#x1EA4;&#x1EA6;&#x1EA8;&#x1EAA;&#x1EAC;&#x1EAE;&#x1EB0;&#x1EB2;&#x1EB4;&#x1EB6;&#x1EB8;&#x1EBA;&#x1EBC;&#x1EBE;&#x1EC0;&#x1EC2;&#x1EC4;&#x1EC6;&#x1EC8;&#x1ECA;&#x1ECC;&#x1ECE;&#x1ED0;&#x1ED2;&#x1ED4;&#x1ED6;&#x1ED8;&#x1EDA;&#x1EDC;&#x1EDE;&#x1EE0;&#x1EE2;&#x1EE4;&#x1EE6;&#x1EE8;&#x1EEA;&#x1EEC;&#x1EEE;&#x1EF0;&#x1EF2;&#x1EF4;&#x1EF6;&#x1EF8;&#x1F08;&#x1F09;&#x1F0A;&#x1F0B;&#x1F0C;&#x1F0D;&#x1F0E;&#x1F0F;&#x1F18;&#x1F19;&#x1F1A;&#x1F1B;&#x1F1C;&#x1F1D;&#x1F28;&#x1F29;&#x1F2A;&#x1F2B;&#x1F2C;&#x1F2D;&#x1F2E;&#x1F2F;&#x1F38;&#x1F39;&#x1F3A;&#x1F3B;&#x1F3C;&#x1F3D;&#x1F3E;&#x1F3F;&#x1F48;&#x1F49;&#x1F4A;&#x1F4B;&#x1F4C;&#x1F4D;&#x1F59;&#x1F5B;&#x1F5D;&#x1F5F;&#x1F68;&#x1F69;&#x1F6A;&#x1F6B;&#x1F6C;&#x1F6D;&#x1F6E;&#x1F6F;&#x1FBA;&#x1FBB;&#x1FC8;&#x1FC9;&#x1FCA;&#x1FCB;&#x1FDA;&#x1FDB;&#x1FF8;&#x1FF9;&#x1FEA;&#x1FEB;&#x1FFA;&#x1FFB;&#x1F88;&#x1F89;&#x1F8A;&#x1F8B;&#x1F8C;&#x1F8D;&#x1F8E;&#x1F8F;&#x1F98;&#x1F99;&#x1F9A;&#x1F9B;&#x1F9C;&#x1F9D;&#x1F9E;&#x1F9F;&#x1FA8;&#x1FA9;&#x1FAA;&#x1FAB;&#x1FAC;&#x1FAD;&#x1FAE;&#x1FAF;&#x1FB8;&#x1FB9;&#x1FBC;&#x0399;&#x1FCC;&#x1FD8;&#x1FD9;&#x1FE8;&#x1FE9;&#x1FEC;&#x1FFC;&#x2160;&#x2161;&#x2162;&#x2163;&#x2164;&#x2165;&#x2166;&#x2167;&#x2168;&#x2169;&#x216A;&#x216B;&#x216C;&#x216D;&#x216E;&#x216F;&#x24B6;&#x24B7;&#x24B8;&#x24B9;&#x24BA;&#x24BB;&#x24BC;&#x24BD;&#x24BE;&#x24BF;&#x24C0;&#x24C1;&#x24C2;&#x24C3;&#x24C4;&#x24C5;&#x24C6;&#x24C7;&#x24C8;&#x24C9;&#x24CA;&#x24CB;&#x24CC;&#x24CD;&#x24CE;&#x24CF;&#xFF21;&#xFF22;&#xFF23;&#xFF24;&#xFF25;&#xFF26;&#xFF27;&#xFF28;&#xFF29;&#xFF2A;&#xFF2B;&#xFF2C;&#xFF2D;&#xFF2E;&#xFF2F;&#xFF30;&#xFF31;&#xFF32;&#xFF33;&#xFF34;&#xFF35;&#xFF36;&#xFF37;&#xFF38;&#xFF39;&#xFF3A;&#x10400;&#x10401;&#x10402;&#x10403;&#x10404;&#x10405;&#x10406;&#x10407;&#x10408;&#x10409;&#x1040A;&#x1040B;&#x1040C;&#x1040D;&#x1040E;&#x1040F;&#x10410;&#x10411;&#x10412;&#x10413;&#x10414;&#x10415;&#x10416;&#x10417;&#x10418;&#x10419;&#x1041A;&#x1041B;&#x1041C;&#x1041D;&#x1041E;&#x1041F;&#x10420;&#x10421;&#x10422;&#x10423;&#x10424;&#x10425;'"/>
  39. <xsl:variable name="xsltsl-str-digits" select="'0123456789'"/>
  40. <!-- space (#x20) characters, carriage returns, line feeds, or tabs. -->
  41. <xsl:variable name="xsltsl-str-ws" select="'&#x20;&#x9;&#xD;&#xA;'"/>
  42. <doc:template name="str:to-upper" xmlns="">
  43. <refpurpose>Make string uppercase</refpurpose>
  44. <refdescription>
  45. <para>Converts all lowercase letters to uppercase.</para>
  46. </refdescription>
  47. <refparameter>
  48. <variablelist>
  49. <varlistentry>
  50. <term>text</term>
  51. <listitem>
  52. <para>The string to be converted</para>
  53. </listitem>
  54. </varlistentry>
  55. </variablelist>
  56. </refparameter>
  57. <refreturn>
  58. <para>Returns string with all uppercase letters.</para>
  59. </refreturn>
  60. </doc:template>
  61. <xsl:template name="str:to-upper">
  62. <xsl:param name="text"/>
  63. <!-- Below exception is extracted from unicode's SpecialCasing.txt
  64. file. It's the german lowercase "eszett" (the thing looking
  65. like a greek beta) that's to become "SS" in uppercase (note:
  66. that are *two* characters, that's why it doesn't fit in the
  67. list of upper/lowercase characters). There are more
  68. characters in that file (103, excluding the locale-specific
  69. ones), but they seemed to be much less used to me and they
  70. add up to a hellish long stylesheet.... - Reinout -->
  71. <xsl:param name="modified-text">
  72. <xsl:call-template name="str:subst">
  73. <xsl:with-param name="text">
  74. <xsl:value-of select="$text"/>
  75. </xsl:with-param>
  76. <xsl:with-param name="replace">
  77. <xsl:text>&#x00DF;</xsl:text>
  78. </xsl:with-param>
  79. <xsl:with-param name="with">
  80. <xsl:text>&#x0053;</xsl:text>
  81. <xsl:text>&#x0053;</xsl:text>
  82. </xsl:with-param>
  83. </xsl:call-template>
  84. </xsl:param>
  85. <xsl:value-of select="translate($modified-text, $xsltsl-str-lower, $xsltsl-str-upper)"/>
  86. </xsl:template>
  87. <doc:template name="str:to-lower" xmlns="">
  88. <refpurpose>Make string lowercase</refpurpose>
  89. <refdescription>
  90. <para>Converts all uppercase letters to lowercase.</para>
  91. </refdescription>
  92. <refparameter>
  93. <variablelist>
  94. <varlistentry>
  95. <term>text</term>
  96. <listitem>
  97. <para>The string to be converted</para>
  98. </listitem>
  99. </varlistentry>
  100. </variablelist>
  101. </refparameter>
  102. <refreturn>
  103. <para>Returns string with all lowercase letters.</para>
  104. </refreturn>
  105. </doc:template>
  106. <xsl:template name="str:to-lower">
  107. <xsl:param name="text"/>
  108. <xsl:value-of select="translate($text, $xsltsl-str-upper, $xsltsl-str-lower)"/>
  109. </xsl:template>
  110. <doc:template name="str:capitalise" xmlns="">
  111. <refpurpose>Capitalise string</refpurpose>
  112. <refdescription>
  113. <para>Converts first character of string to an uppercase letter. All remaining characters are converted to lowercase.</para>
  114. </refdescription>
  115. <refparameter>
  116. <variablelist>
  117. <varlistentry>
  118. <term>text</term>
  119. <listitem>
  120. <para>The string to be capitalised</para>
  121. </listitem>
  122. </varlistentry>
  123. <varlistentry>
  124. <term>all</term>
  125. <listitem>
  126. <para>Boolean controlling whether all words in the string are capitalised.</para>
  127. <para>Default is true.</para>
  128. </listitem>
  129. </varlistentry>
  130. </variablelist>
  131. </refparameter>
  132. <refreturn>
  133. <para>Returns string with first character uppcase and all remaining characters lowercase.</para>
  134. </refreturn>
  135. </doc:template>
  136. <xsl:template name="str:capitalise">
  137. <xsl:param name="text"/>
  138. <xsl:param name="all" select="true()"/>
  139. <xsl:choose>
  140. <xsl:when test="$all and (contains($text, ' ') or contains($text, ' ') or contains($text, '&#10;'))">
  141. <xsl:variable name="firstword">
  142. <xsl:call-template name="str:substring-before-first">
  143. <xsl:with-param name="text" select="$text"/>
  144. <xsl:with-param name="chars" select="$xsltsl-str-ws"/>
  145. </xsl:call-template>
  146. </xsl:variable>
  147. <xsl:call-template name="str:capitalise">
  148. <xsl:with-param name="text">
  149. <xsl:value-of select="$firstword"/>
  150. </xsl:with-param>
  151. <xsl:with-param name="all" select="false()"/>
  152. </xsl:call-template>
  153. <xsl:value-of select="substring($text, string-length($firstword) + 1, 1)"/>
  154. <xsl:call-template name="str:capitalise">
  155. <xsl:with-param name="text">
  156. <xsl:value-of select="substring($text, string-length($firstword) + 2)"/>
  157. </xsl:with-param>
  158. </xsl:call-template>
  159. </xsl:when>
  160. <xsl:otherwise>
  161. <xsl:call-template name="str:to-upper">
  162. <xsl:with-param name="text" select="substring($text, 1, 1)"/>
  163. </xsl:call-template>
  164. <xsl:call-template name="str:to-lower">
  165. <xsl:with-param name="text" select="substring($text, 2)"/>
  166. </xsl:call-template>
  167. </xsl:otherwise>
  168. </xsl:choose>
  169. </xsl:template>
  170. <doc:template name="str:to-camelcase" xmlns="">
  171. <refpurpose>Convert a string to one camelcase word</refpurpose>
  172. <refdescription>
  173. <para>Converts a string to one lowerCamelCase or UpperCamelCase
  174. word, depending on the setting of the "upper"
  175. parameter. UpperCamelCase is also called MixedCase while
  176. lowerCamelCase is also called just camelCase. The template
  177. removes any spaces, tabs and slashes, but doesn't deal with
  178. other punctuation. It's purpose is to convert strings like
  179. "hollow timber flush door" to a term suitable as identifier or
  180. XML tag like "HollowTimberFlushDoor".
  181. </para>
  182. </refdescription>
  183. <refparameter>
  184. <variablelist>
  185. <varlistentry>
  186. <term>text</term>
  187. <listitem>
  188. <para>The string to be capitalised</para>
  189. </listitem>
  190. </varlistentry>
  191. <varlistentry>
  192. <term>upper</term>
  193. <listitem>
  194. <para>Boolean controlling whether the string becomes an
  195. UpperCamelCase word or a lowerCamelCase word.</para>
  196. <para>Default is true.</para>
  197. </listitem>
  198. </varlistentry>
  199. </variablelist>
  200. </refparameter>
  201. <refreturn>
  202. <para>Returns string with first character uppcase and all remaining characters lowercase.</para>
  203. </refreturn>
  204. </doc:template>
  205. <xsl:template name="str:to-camelcase">
  206. <xsl:param name="text"/>
  207. <xsl:param name="upper" select="true()"/>
  208. <!-- First change all 'strange' characters to spaces -->
  209. <xsl:param name="string-with-only-spaces">
  210. <xsl:value-of select="translate($text,concat($xsltsl-str-ws,'/'),' ')"/>
  211. </xsl:param>
  212. <!-- Then process them -->
  213. <xsl:param name="before-space-removal">
  214. <xsl:variable name="firstword">
  215. <xsl:call-template name="str:substring-before-first">
  216. <xsl:with-param name="text" select="$string-with-only-spaces"/>
  217. <xsl:with-param name="chars" select="$xsltsl-str-ws"/>
  218. </xsl:call-template>
  219. </xsl:variable>
  220. <xsl:choose>
  221. <xsl:when test="$upper">
  222. <xsl:call-template name="str:to-upper">
  223. <xsl:with-param name="text" select="substring($firstword, 1, 1)"/>
  224. </xsl:call-template>
  225. <xsl:call-template name="str:to-lower">
  226. <xsl:with-param name="text" select="substring($firstword, 2)"/>
  227. </xsl:call-template>
  228. </xsl:when>
  229. <xsl:otherwise>
  230. <xsl:call-template name="str:to-lower">
  231. <xsl:with-param name="text" select="$firstword"/>
  232. </xsl:call-template>
  233. </xsl:otherwise>
  234. </xsl:choose>
  235. <xsl:call-template name="str:capitalise">
  236. <xsl:with-param name="text">
  237. <xsl:value-of select="substring($string-with-only-spaces, string-length($firstword) + 2)"/>
  238. </xsl:with-param>
  239. <xsl:with-param name="all" select="true()"/>
  240. </xsl:call-template>
  241. </xsl:param>
  242. <xsl:value-of select="translate($before-space-removal,' ','')"/>
  243. </xsl:template>
  244. <doc:template name="str:substring-before-first" xmlns="">
  245. <refpurpose>String extraction</refpurpose>
  246. <refdescription>
  247. <para>Extracts the portion of string 'text' which occurs before any of the characters in string 'chars'.</para>
  248. </refdescription>
  249. <refparameter>
  250. <variablelist>
  251. <varlistentry>
  252. <term>text</term>
  253. <listitem>
  254. <para>The string from which to extract a substring.</para>
  255. </listitem>
  256. </varlistentry>
  257. <varlistentry>
  258. <term>chars</term>
  259. <listitem>
  260. <para>The string containing characters to find.</para>
  261. </listitem>
  262. </varlistentry>
  263. </variablelist>
  264. </refparameter>
  265. <refreturn>
  266. <para>Returns string.</para>
  267. </refreturn>
  268. </doc:template>
  269. <xsl:template name="str:substring-before-first">
  270. <xsl:param name="text"/>
  271. <xsl:param name="chars"/>
  272. <xsl:choose>
  273. <xsl:when test="string-length($text) = 0"/>
  274. <xsl:when test="string-length($chars) = 0">
  275. <xsl:value-of select="$text"/>
  276. </xsl:when>
  277. <xsl:when test="contains($text, substring($chars, 1, 1))">
  278. <xsl:variable name="this" select="substring-before($text, substring($chars, 1, 1))"/>
  279. <xsl:variable name="rest">
  280. <xsl:call-template name="str:substring-before-first">
  281. <xsl:with-param name="text" select="$text"/>
  282. <xsl:with-param name="chars" select="substring($chars, 2)"/>
  283. </xsl:call-template>
  284. </xsl:variable>
  285. <xsl:choose>
  286. <xsl:when test="string-length($this) &lt; string-length($rest)">
  287. <xsl:value-of select="$this"/>
  288. </xsl:when>
  289. <xsl:otherwise>
  290. <xsl:value-of select="$rest"/>
  291. </xsl:otherwise>
  292. </xsl:choose>
  293. </xsl:when>
  294. <xsl:otherwise>
  295. <xsl:call-template name="str:substring-before-first">
  296. <xsl:with-param name="text" select="$text"/>
  297. <xsl:with-param name="chars" select="substring($chars, 2)"/>
  298. </xsl:call-template>
  299. </xsl:otherwise>
  300. </xsl:choose>
  301. </xsl:template>
  302. <doc:template name="str:substring-after-last" xmlns="">
  303. <refpurpose>String extraction</refpurpose>
  304. <refdescription>
  305. <para>Extracts the portion of string 'text' which occurs after the last of the character in string 'chars'.</para>
  306. </refdescription>
  307. <refparameter>
  308. <variablelist>
  309. <varlistentry>
  310. <term>text</term>
  311. <listitem>
  312. <para>The string from which to extract a substring.</para>
  313. </listitem>
  314. </varlistentry>
  315. <varlistentry>
  316. <term>chars</term>
  317. <listitem>
  318. <para>The string containing characters to find.</para>
  319. </listitem>
  320. </varlistentry>
  321. </variablelist>
  322. </refparameter>
  323. <refreturn>
  324. <para>Returns string.</para>
  325. </refreturn>
  326. </doc:template>
  327. <xsl:template name="str:substring-after-last">
  328. <xsl:param name="text"/>
  329. <xsl:param name="chars"/>
  330. <xsl:choose>
  331. <xsl:when test="contains($text, $chars)">
  332. <xsl:variable name="last" select="substring-after($text, $chars)"/>
  333. <xsl:choose>
  334. <xsl:when test="contains($last, $chars)">
  335. <xsl:call-template name="str:substring-after-last">
  336. <xsl:with-param name="text" select="$last"/>
  337. <xsl:with-param name="chars" select="$chars"/>
  338. </xsl:call-template>
  339. </xsl:when>
  340. <xsl:otherwise>
  341. <xsl:value-of select="$last"/>
  342. </xsl:otherwise>
  343. </xsl:choose>
  344. </xsl:when>
  345. <xsl:otherwise>
  346. <xsl:value-of select="$text"/>
  347. </xsl:otherwise>
  348. </xsl:choose>
  349. </xsl:template>
  350. <doc:template name="str:substring-before-last" xmlns="">
  351. <refpurpose>String extraction</refpurpose>
  352. <refdescription>
  353. <para>Extracts the portion of string 'text' which occurs before the first character of the last occurance of string 'chars'.</para>
  354. </refdescription>
  355. <refparameter>
  356. <variablelist>
  357. <varlistentry>
  358. <term>text</term>
  359. <listitem>
  360. <para>The string from which to extract a substring.</para>
  361. </listitem>
  362. </varlistentry>
  363. <varlistentry>
  364. <term>chars</term>
  365. <listitem>
  366. <para>The string containing characters to find.</para>
  367. </listitem>
  368. </varlistentry>
  369. </variablelist>
  370. </refparameter>
  371. <refreturn>
  372. <para>Returns string.</para>
  373. </refreturn>
  374. </doc:template>
  375. <xsl:template name="str:substring-before-last">
  376. <xsl:param name="text"/>
  377. <xsl:param name="chars"/>
  378. <xsl:choose>
  379. <xsl:when test="string-length($text) = 0"/>
  380. <xsl:when test="string-length($chars) = 0">
  381. <xsl:value-of select="$text"/>
  382. </xsl:when>
  383. <xsl:when test="contains($text, $chars)">
  384. <xsl:call-template name="str:substring-before-last-aux">
  385. <xsl:with-param name="text" select="$text"/>
  386. <xsl:with-param name="chars" select="$chars"/>
  387. </xsl:call-template>
  388. </xsl:when>
  389. <xsl:otherwise>
  390. <xsl:value-of select="$text"/>
  391. </xsl:otherwise>
  392. </xsl:choose>
  393. </xsl:template>
  394. <xsl:template name="str:substring-before-last-aux">
  395. <xsl:param name="text"/>
  396. <xsl:param name="chars"/>
  397. <xsl:choose>
  398. <xsl:when test="string-length($text) = 0"/>
  399. <xsl:when test="contains($text, $chars)">
  400. <xsl:variable name="after">
  401. <xsl:call-template name="str:substring-before-last-aux">
  402. <xsl:with-param name="text" select="substring-after($text, $chars)"/>
  403. <xsl:with-param name="chars" select="$chars"/>
  404. </xsl:call-template>
  405. </xsl:variable>
  406. <xsl:value-of select="substring-before($text, $chars)"/>
  407. <xsl:if test="string-length($after) &gt; 0">
  408. <xsl:value-of select="$chars"/>
  409. <xsl:copy-of select="$after"/>
  410. </xsl:if>
  411. </xsl:when>
  412. <xsl:otherwise/>
  413. </xsl:choose>
  414. </xsl:template>
  415. <doc:template name="str:subst" xmlns="">
  416. <refpurpose>String substitution</refpurpose>
  417. <refdescription>
  418. <para>Substitute 'replace' for 'with' in string 'text'.</para>
  419. </refdescription>
  420. <refparameter>
  421. <variablelist>
  422. <varlistentry>
  423. <term>text</term>
  424. <listitem>
  425. <para>The string upon which to perform substitution.</para>
  426. </listitem>
  427. </varlistentry>
  428. <varlistentry>
  429. <term>replace</term>
  430. <listitem>
  431. <para>The string to substitute.</para>
  432. </listitem>
  433. </varlistentry>
  434. <varlistentry>
  435. <term>with</term>
  436. <listitem>
  437. <para>The string to be substituted.</para>
  438. </listitem>
  439. </varlistentry>
  440. <varlistentry>
  441. <term>disable-output-escaping</term>
  442. <listitem>
  443. <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>
  444. </listitem>
  445. </varlistentry>
  446. </variablelist>
  447. </refparameter>
  448. <refreturn>
  449. <para>Returns string.</para>
  450. </refreturn>
  451. </doc:template>
  452. <xsl:template name="str:subst">
  453. <xsl:param name="text"/>
  454. <xsl:param name="replace"/>
  455. <xsl:param name="with"/>
  456. <xsl:param name='disable-output-escaping'>no</xsl:param>
  457. <xsl:choose>
  458. <xsl:when test="string-length($replace) = 0 and $disable-output-escaping = 'yes'">
  459. <xsl:value-of select="$text" disable-output-escaping='yes'/>
  460. </xsl:when>
  461. <xsl:when test="string-length($replace) = 0">
  462. <xsl:value-of select="$text"/>
  463. </xsl:when>
  464. <xsl:when test="contains($text, $replace)">
  465. <xsl:variable name="before" select="substring-before($text, $replace)"/>
  466. <xsl:variable name="after" select="substring-after($text, $replace)"/>
  467. <xsl:choose>
  468. <xsl:when test='$disable-output-escaping = "yes"'>
  469. <xsl:value-of select="$before" disable-output-escaping="yes"/>
  470. <xsl:value-of select="$with" disable-output-escaping="yes"/>
  471. </xsl:when>
  472. <xsl:otherwise>
  473. <xsl:value-of select="$before"/>
  474. <xsl:value-of select="$with"/>
  475. </xsl:otherwise>
  476. </xsl:choose>
  477. <xsl:call-template name="str:subst">
  478. <xsl:with-param name="text" select="$after"/>
  479. <xsl:with-param name="replace" select="$replace"/>
  480. <xsl:with-param name="with" select="$with"/>
  481. <xsl:with-param name="disable-output-escaping" select="$disable-output-escaping"/>
  482. </xsl:call-template>
  483. </xsl:when>
  484. <xsl:when test='$disable-output-escaping = "yes"'>
  485. <xsl:value-of select="$text" disable-output-escaping="yes"/>
  486. </xsl:when>
  487. <xsl:otherwise>
  488. <xsl:value-of select="$text"/>
  489. </xsl:otherwise>
  490. </xsl:choose>
  491. </xsl:template>
  492. <doc:template name="str:count-substring" xmlns="">
  493. <refpurpose>Count Substrings</refpurpose>
  494. <refdescription>
  495. <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>
  496. </refdescription>
  497. <example>
  498. <title>Counting Lines</title>
  499. <programlisting><![CDATA[
  500. <xsl:call-template name="str:count-substring">
  501. <xsl:with-param name="text" select="$mytext"/>
  502. <xsl:with-param name="chars" select="'&#x0a;'"/>
  503. </xsl:call-template>
  504. ]]></programlisting>
  505. </example>
  506. <refparameter>
  507. <variablelist>
  508. <varlistentry>
  509. <term>text</term>
  510. <listitem>
  511. <para>The source string.</para>
  512. </listitem>
  513. </varlistentry>
  514. <varlistentry>
  515. <term>chars</term>
  516. <listitem>
  517. <para>The substring to count.</para>
  518. </listitem>
  519. </varlistentry>
  520. </variablelist>
  521. </refparameter>
  522. <refreturn>
  523. <para>Returns a non-negative integer value.</para>
  524. </refreturn>
  525. </doc:template>
  526. <xsl:template name="str:count-substring">
  527. <xsl:param name="text"/>
  528. <xsl:param name="chars"/>
  529. <xsl:choose>
  530. <xsl:when test="string-length($text) = 0 or string-length($chars) = 0">
  531. <xsl:text>0</xsl:text>
  532. </xsl:when>
  533. <xsl:when test="contains($text, $chars)">
  534. <xsl:variable name="remaining">
  535. <xsl:call-template name="str:count-substring">
  536. <xsl:with-param name="text" select="substring-after($text, $chars)"/>
  537. <xsl:with-param name="chars" select="$chars"/>
  538. </xsl:call-template>
  539. </xsl:variable>
  540. <xsl:value-of select="$remaining + 1"/>
  541. </xsl:when>
  542. <xsl:otherwise>
  543. <xsl:text>0</xsl:text>
  544. </xsl:otherwise>
  545. </xsl:choose>
  546. </xsl:template>
  547. <doc:template name="str:substring-after-at" xmlns="">
  548. <refpurpose>String extraction</refpurpose>
  549. <refdescription>
  550. <para>Extracts the portion of a 'char' delimited 'text' string "array" at a given 'position'.</para>
  551. </refdescription>
  552. <refparameter>
  553. <variablelist>
  554. <varlistentry>
  555. <term>text</term>
  556. <listitem>
  557. <para>The string from which to extract a substring.</para>
  558. </listitem>
  559. </varlistentry>
  560. <varlistentry>
  561. <term>chars</term>
  562. <listitem>
  563. <para>delimiters</para>
  564. </listitem>
  565. </varlistentry>
  566. <varlistentry>
  567. <term>position</term>
  568. <listitem>
  569. <para>position of the elements</para>
  570. </listitem>
  571. </varlistentry>
  572. <varlistentry>
  573. <term>all</term>
  574. <listitem>
  575. <para>If true all of the remaining string is returned, otherwise only the element at the given position is returned. Default: false().</para>
  576. </listitem>
  577. </varlistentry>
  578. </variablelist>
  579. </refparameter>
  580. <refreturn>
  581. <para>Returns string.</para>
  582. </refreturn>
  583. </doc:template>
  584. <xsl:template name="str:substring-after-at">
  585. <xsl:param name="text"/>
  586. <xsl:param name="chars"/>
  587. <xsl:param name="position"/>
  588. <xsl:param name="all" select='false()'/>
  589. <xsl:choose>
  590. <xsl:when test='number($position) = 0 and $all'>
  591. <xsl:value-of select='$text'/>
  592. </xsl:when>
  593. <xsl:when test='number($position) = 0 and not($chars)'>
  594. <xsl:value-of select='$text'/>
  595. </xsl:when>
  596. <xsl:when test='number($position) = 0 and not(contains($text, $chars))'>
  597. <xsl:value-of select='$text'/>
  598. </xsl:when>
  599. <xsl:when test='not(contains($text, $chars))'>
  600. </xsl:when>
  601. <xsl:when test="number($position) = 0">
  602. <xsl:value-of select="substring-before($text, $chars)"/>
  603. </xsl:when>
  604. <xsl:otherwise>
  605. <xsl:call-template name="str:substring-after-at">
  606. <xsl:with-param name="text" select="substring-after($text, $chars)"/>
  607. <xsl:with-param name="chars" select="$chars"/>
  608. <xsl:with-param name="all" select="$all"/>
  609. <xsl:with-param name="position" select="$position - 1"/>
  610. </xsl:call-template>
  611. </xsl:otherwise>
  612. </xsl:choose>
  613. </xsl:template>
  614. <doc:template name="str:substring-before-at" xmlns="">
  615. <refpurpose>String extraction</refpurpose>
  616. <refdescription>
  617. <para>Extracts the portion of a 'char' delimited 'text' string "array" at a given 'position' </para>
  618. </refdescription>
  619. <refparameter>
  620. <variablelist>
  621. <varlistentry>
  622. <term>text</term>
  623. <listitem>
  624. <para>The string from which to extract a substring.</para>
  625. </listitem>
  626. </varlistentry>
  627. <varlistentry>
  628. <term>chars</term>
  629. <listitem>
  630. <para>delimiters</para>
  631. </listitem>
  632. </varlistentry>
  633. <varlistentry>
  634. <term>position</term>
  635. <listitem>
  636. <para>position of the elements</para>
  637. </listitem>
  638. </varlistentry>
  639. </variablelist>
  640. </refparameter>
  641. <refreturn>
  642. <para>Returns string.</para>
  643. </refreturn>
  644. </doc:template>
  645. <xsl:template name="str:substring-before-at">
  646. <xsl:param name="text"/>
  647. <xsl:param name="chars"/>
  648. <xsl:param name="position"/>
  649. <xsl:choose>
  650. <xsl:when test="$position &lt;= 0"/>
  651. <xsl:when test="not(contains($text, $chars))"/>
  652. <xsl:otherwise>
  653. <xsl:value-of select='substring-before($text, $chars)'/>
  654. <xsl:value-of select='$chars'/>
  655. <xsl:call-template name="str:substring-before-at">
  656. <xsl:with-param name="text" select="substring-after($text, $chars)"/>
  657. <xsl:with-param name="position" select="$position - 1"/>
  658. <xsl:with-param name="chars" select="$chars"/>
  659. </xsl:call-template>
  660. </xsl:otherwise>
  661. </xsl:choose>
  662. </xsl:template>
  663. <doc:template name="str:insert-at" xmlns="">
  664. <refpurpose>String insertion</refpurpose>
  665. <refdescription>
  666. <para>Insert 'chars' into "text' at any given "position'</para>
  667. </refdescription>
  668. <refparameter>
  669. <variablelist>
  670. <varlistentry>
  671. <term>text</term>
  672. <listitem>
  673. <para>The string upon which to perform insertion</para>
  674. </listitem>
  675. </varlistentry>
  676. <varlistentry>
  677. <term>position</term>
  678. <listitem>
  679. <para>the position where insertion will be performed</para>
  680. </listitem>
  681. </varlistentry>
  682. <varlistentry>
  683. <term>with</term>
  684. <listitem>
  685. <para>The string to be inserted</para>
  686. </listitem>
  687. </varlistentry>
  688. </variablelist>
  689. </refparameter>
  690. <refreturn>
  691. <para>Returns string.</para>
  692. </refreturn>
  693. </doc:template>
  694. <xsl:template name="str:insert-at">
  695. <xsl:param name="text"/>
  696. <xsl:param name="position"/>
  697. <xsl:param name="chars"/>
  698. <xsl:variable name="firstpart" select="substring($text, 0, $position)"/>
  699. <xsl:variable name="secondpart" select="substring($text, $position, string-length($text))"/>
  700. <xsl:value-of select="concat($firstpart, $chars, $secondpart)"/>
  701. </xsl:template>
  702. <doc:template name="str:backward" xmlns="">
  703. <refpurpose>String reversal</refpurpose>
  704. <refdescription>
  705. <para>Reverse the content of a given string</para>
  706. </refdescription>
  707. <refparameter>
  708. <variablelist>
  709. <varlistentry>
  710. <term>text</term>
  711. <listitem>
  712. <para>The string to be reversed</para>
  713. </listitem>
  714. </varlistentry>
  715. </variablelist>
  716. </refparameter>
  717. <refreturn>
  718. <para>Returns string.</para>
  719. </refreturn>
  720. </doc:template>
  721. <xsl:template name="str:backward">
  722. <xsl:param name="text"/>
  723. <xsl:variable name="mirror">
  724. <xsl:call-template name="str:build-mirror">
  725. <xsl:with-param name="text" select="$text"/>
  726. <xsl:with-param name="position" select="string-length($text)"/>
  727. </xsl:call-template>
  728. </xsl:variable>
  729. <xsl:value-of select="substring($mirror, string-length($text) + 1, string-length($text))"/>
  730. </xsl:template>
  731. <xsl:template name="str:build-mirror">
  732. <xsl:param name="text"/>
  733. <xsl:param name="position"/>
  734. <xsl:choose>
  735. <xsl:when test="$position &gt; 0">
  736. <xsl:call-template name="str:build-mirror">
  737. <xsl:with-param name="text" select="concat($text, substring($text, $position, 1))"/>
  738. <xsl:with-param name="position" select="$position - 1"/>
  739. </xsl:call-template>
  740. </xsl:when>
  741. <xsl:otherwise>
  742. <xsl:value-of select="$text"/>
  743. </xsl:otherwise>
  744. </xsl:choose>
  745. </xsl:template>
  746. <doc:template name="str:justify" xmlns="">
  747. <refpurpose>Format a string</refpurpose>
  748. <refdescription>
  749. <para>Inserts newlines and spaces into a string to format it as a block of text.</para>
  750. </refdescription>
  751. <refparameter>
  752. <variablelist>
  753. <varlistentry>
  754. <term>text</term>
  755. <listitem>
  756. <para>String to be formatted.</para>
  757. </listitem>
  758. </varlistentry>
  759. <varlistentry>
  760. <term>max</term>
  761. <listitem>
  762. <para>Maximum line length.</para>
  763. </listitem>
  764. </varlistentry>
  765. <varlistentry>
  766. <term>indent</term>
  767. <listitem>
  768. <para>Number of spaces to insert at the beginning of each line.</para>
  769. </listitem>
  770. </varlistentry>
  771. <varlistentry>
  772. <term>justify</term>
  773. <listitem>
  774. <para>Justify left, right or both. Not currently implemented (fixed at "left").</para>
  775. </listitem>
  776. </varlistentry>
  777. </variablelist>
  778. </refparameter>
  779. <refreturn>
  780. <para>Formatted block of text.</para>
  781. </refreturn>
  782. </doc:template>
  783. <xsl:template name='str:justify'>
  784. <xsl:param name='text'/>
  785. <xsl:param name='max' select='"80"'/>
  786. <xsl:param name='indent' select='"0"'/>
  787. <xsl:param name='justify' select='"left"'/>
  788. <xsl:choose>
  789. <xsl:when test='string-length($text) = 0 or $max &lt;= 0'/>
  790. <xsl:when test='string-length($text) > $max and contains($text, " ") and string-length(substring-before($text, " ")) > $max'>
  791. <xsl:call-template name='str:generate-string'>
  792. <xsl:with-param name='text' select='" "'/>
  793. <xsl:with-param name='count' select='$indent'/>
  794. </xsl:call-template>
  795. <xsl:value-of select='substring-before($text, " ")'/>
  796. <xsl:text>
  797. </xsl:text>
  798. <xsl:call-template name='str:justify'>
  799. <xsl:with-param name='text' select='substring-after($text, " ")'/>
  800. <xsl:with-param name='max' select='$max'/>
  801. <xsl:with-param name='indent' select='$indent'/>
  802. <xsl:with-param name='justify' select='$justify'/>
  803. </xsl:call-template>
  804. </xsl:when>
  805. <xsl:when test='string-length($text) > $max and contains($text, " ")'>
  806. <xsl:variable name='first'>
  807. <xsl:call-template name='str:substring-before-last'>
  808. <xsl:with-param name='text' select='substring($text, 1, $max)'/>
  809. <xsl:with-param name='chars' select='" "'/>
  810. </xsl:call-template>
  811. </xsl:variable>
  812. <xsl:call-template name='str:generate-string'>
  813. <xsl:with-param name='text' select='" "'/>
  814. <xsl:with-param name='count' select='$indent'/>
  815. </xsl:call-template>
  816. <xsl:value-of select='$first'/>
  817. <xsl:text>
  818. </xsl:text>
  819. <xsl:call-template name='str:justify'>
  820. <xsl:with-param name='text' select='substring($text, string-length($first) + 2)'/>
  821. <xsl:with-param name='max' select='$max'/>
  822. <xsl:with-param name='indent' select='$indent'/>
  823. <xsl:with-param name='justify' select='$justify'/>
  824. </xsl:call-template>
  825. </xsl:when>
  826. <xsl:otherwise>
  827. <xsl:call-template name='str:generate-string'>
  828. <xsl:with-param name='text' select='" "'/>
  829. <xsl:with-param name='count' select='$indent'/>
  830. </xsl:call-template>
  831. <xsl:value-of select='$text'/>
  832. </xsl:otherwise>
  833. </xsl:choose>
  834. </xsl:template>
  835. <doc:template name="str:character-first" xmlns="">
  836. <refpurpose>Find first occurring character in a string</refpurpose>
  837. <refdescription>
  838. <para>Finds which of the given characters occurs first in a string.</para>
  839. </refdescription>
  840. <refparameter>
  841. <variablelist>
  842. <varlistentry>
  843. <term>text</term>
  844. <listitem>
  845. <para>The source string.</para>
  846. </listitem>
  847. </varlistentry>
  848. <varlistentry>
  849. <term>chars</term>
  850. <listitem>
  851. <para>The characters to search for.</para>
  852. </listitem>
  853. </varlistentry>
  854. </variablelist>
  855. </refparameter>
  856. </doc:template>
  857. <xsl:template name="str:character-first">
  858. <xsl:param name="text"/>
  859. <xsl:param name="chars"/>
  860. <xsl:choose>
  861. <xsl:when test="string-length($text) = 0 or string-length($chars) = 0"/>
  862. <xsl:when test="contains($text, substring($chars, 1, 1))">
  863. <xsl:variable name="next-character">
  864. <xsl:call-template name="str:character-first">
  865. <xsl:with-param name="text" select="$text"/>
  866. <xsl:with-param name="chars" select="substring($chars, 2)"/>
  867. </xsl:call-template>
  868. </xsl:variable>
  869. <xsl:choose>
  870. <xsl:when test="string-length($next-character)">
  871. <xsl:variable name="first-character-position" select="string-length(substring-before($text, substring($chars, 1, 1)))"/>
  872. <xsl:variable name="next-character-position" select="string-length(substring-before($text, $next-character))"/>
  873. <xsl:choose>
  874. <xsl:when test="$first-character-position &lt; $next-character-position">
  875. <xsl:value-of select="substring($chars, 1, 1)"/>
  876. </xsl:when>
  877. <xsl:otherwise>
  878. <xsl:value-of select="$next-character"/>
  879. </xsl:otherwise>
  880. </xsl:choose>
  881. </xsl:when>
  882. <xsl:otherwise>
  883. <xsl:value-of select="substring($chars, 1, 1)"/>
  884. </xsl:otherwise>
  885. </xsl:choose>
  886. </xsl:when>
  887. <xsl:otherwise>
  888. <xsl:call-template name="str:character-first">
  889. <xsl:with-param name="text" select="$text"/>
  890. <xsl:with-param name="chars" select="substring($chars, 2)"/>
  891. </xsl:call-template>
  892. </xsl:otherwise>
  893. </xsl:choose>
  894. </xsl:template>
  895. <doc:template name="str:string-match" xmlns="">
  896. <refpurpose>Match A String To A Pattern</refpurpose>
  897. <refdescription>
  898. <para>Performs globbing-style pattern matching on a string.</para>
  899. </refdescription>
  900. <example>
  901. <title>Match Pattern</title>
  902. <programlisting><![CDATA[
  903. <xsl:call-template name="str:string-match">
  904. <xsl:with-param name="text" select="$mytext"/>
  905. <xsl:with-param name="pattern" select="'abc*def?g'"/>
  906. </xsl:call-template>
  907. ]]></programlisting>
  908. </example>
  909. <refparameter>
  910. <variablelist>
  911. <varlistentry>
  912. <term>text</term>
  913. <listitem>
  914. <para>The source string.</para>
  915. </listitem>
  916. </varlistentry>
  917. <varlistentry>
  918. <term>pattern</term>
  919. <listitem>
  920. <para>The pattern to match against. Certain characters have special meaning:</para>
  921. <variablelist>
  922. <varlistentry>
  923. <term>*</term>
  924. <listitem>
  925. <para>Matches zero or more characters.</para>
  926. </listitem>
  927. </varlistentry>
  928. <varlistentry>
  929. <term>?</term>
  930. <listitem>
  931. <para>Matches a single character.</para>
  932. </listitem>
  933. </varlistentry>
  934. <varlistentry>
  935. <term>\</term>
  936. <listitem>
  937. <para>Character escape. The next character is taken as a literal character.</para>
  938. </listitem>
  939. </varlistentry>
  940. </variablelist>
  941. </listitem>
  942. </varlistentry>
  943. </variablelist>
  944. </refparameter>
  945. <refreturn>
  946. <para>Returns "1" if the string matches the pattern, "0" otherwise.</para>
  947. </refreturn>
  948. </doc:template>
  949. <xsl:template name="str:string-match">
  950. <xsl:param name="text"/>
  951. <xsl:param name="pattern"/>
  952. <xsl:choose>
  953. <xsl:when test="$pattern = '*'">
  954. <!-- Special case: always matches -->
  955. <xsl:text>1</xsl:text>
  956. </xsl:when>
  957. <xsl:when test="string-length($text) = 0 and string-length($pattern) = 0">
  958. <xsl:text>1</xsl:text>
  959. </xsl:when>
  960. <xsl:when test="string-length($text) = 0 or string-length($pattern) = 0">
  961. <xsl:text>0</xsl:text>
  962. </xsl:when>
  963. <xsl:otherwise>
  964. <xsl:variable name='before-special'>
  965. <xsl:call-template name='str:substring-before-first'>
  966. <xsl:with-param name='text' select='$pattern'/>
  967. <xsl:with-param name='chars' select='"*?\"'/>
  968. </xsl:call-template>
  969. </xsl:variable>
  970. <xsl:variable name='special'>
  971. <xsl:call-template name='str:character-first'>
  972. <xsl:with-param name='text' select='$pattern'/>
  973. <xsl:with-param name='chars' select='"*?\"'/>
  974. </xsl:call-template>
  975. </xsl:variable>
  976. <xsl:variable name='new-text' select='substring($text, string-length($before-special) + 1)'/>
  977. <xsl:variable name='new-pattern' select='substring($pattern, string-length($before-special) + 1)'/>
  978. <xsl:choose>
  979. <xsl:when test="not(starts-with($text, $before-special))">
  980. <!-- Verbatim characters don't match -->
  981. <xsl:text>0</xsl:text>
  982. </xsl:when>
  983. <xsl:when test="$special = '*' and string-length($new-pattern) = 1">
  984. <xsl:text>1</xsl:text>
  985. </xsl:when>
  986. <xsl:when test="$special = '*'">
  987. <xsl:call-template name='str:match-postfix'>
  988. <xsl:with-param name='text' select='$new-text'/>
  989. <xsl:with-param name='pattern' select='substring($new-pattern, 2)'/>
  990. </xsl:call-template>
  991. </xsl:when>
  992. <xsl:when test="$special = '?'">
  993. <xsl:call-template name="str:string-match">
  994. <xsl:with-param name='text' select='substring($new-text, 2)'/>
  995. <xsl:with-param name='pattern' select='substring($new-pattern, 2)'/>
  996. </xsl:call-template>
  997. </xsl:when>
  998. <xsl:when test="$special = '\' and substring($new-text, 1, 1) = substring($new-pattern, 2, 1)">
  999. <xsl:call-template name="str:string-match">
  1000. <xsl:with-param name='text' select='substring($new-text, 2)'/>
  1001. <xsl:with-param name='pattern' select='substring($new-pattern, 3)'/>
  1002. </xsl:call-template>
  1003. </xsl:when>
  1004. <xsl:when test="$special = '\' and substring($new-text, 1, 1) != substring($new-pattern, 2, 1)">
  1005. <xsl:text>0</xsl:text>
  1006. </xsl:when>
  1007. <xsl:otherwise>
  1008. <!-- There were no special characters in the pattern -->
  1009. <xsl:choose>
  1010. <xsl:when test='$text = $pattern'>
  1011. <xsl:text>1</xsl:text>
  1012. </xsl:when>
  1013. <xsl:otherwise>
  1014. <xsl:text>0</xsl:text>
  1015. </xsl:otherwise>
  1016. </xsl:choose>
  1017. </xsl:otherwise>
  1018. </xsl:choose>
  1019. </xsl:otherwise>
  1020. </xsl:choose>
  1021. </xsl:template>
  1022. <xsl:template name="str:match-postfix">
  1023. <xsl:param name="text"/>
  1024. <xsl:param name="pattern"/>
  1025. <xsl:variable name='result'>
  1026. <xsl:call-template name='str:string-match'>
  1027. <xsl:with-param name='text' select='$text'/>
  1028. <xsl:with-param name='pattern' select='$pattern'/>
  1029. </xsl:call-template>
  1030. </xsl:variable>
  1031. <xsl:choose>
  1032. <xsl:when test='$result = "1"'>
  1033. <xsl:value-of select='$result'/>
  1034. </xsl:when>
  1035. <xsl:when test='string-length($text) = 0'>
  1036. <xsl:text>0</xsl:text>
  1037. </xsl:when>
  1038. <xsl:otherwise>
  1039. <xsl:call-template name='str:match-postfix'>
  1040. <xsl:with-param name='text' select='substring($text, 2)'/>
  1041. <xsl:with-param name='pattern' select='$pattern'/>
  1042. </xsl:call-template>
  1043. </xsl:otherwise>
  1044. </xsl:choose>
  1045. </xsl:template>
  1046. <doc:template name="str:generate-string" xmlns="">
  1047. <refpurpose>Create A Repeating Sequence of Characters</refpurpose>
  1048. <refdescription>
  1049. <para>Repeats a string a given number of times.</para>
  1050. </refdescription>
  1051. <refparameter>
  1052. <variablelist>
  1053. <varlistentry>
  1054. <term>text</term>
  1055. <listitem>
  1056. <para>The string to repeat.</para>
  1057. </listitem>
  1058. </varlistentry>
  1059. <varlistentry>
  1060. <term>count</term>
  1061. <listitem>
  1062. <para>The number of times to repeat the string.</para>
  1063. </listitem>
  1064. </varlistentry>
  1065. </variablelist>
  1066. </refparameter>
  1067. </doc:template>
  1068. <xsl:template name="str:generate-string">
  1069. <xsl:param name="text"/>
  1070. <xsl:param name="count"/>
  1071. <xsl:choose>
  1072. <xsl:when test="string-length($text) = 0 or $count &lt;= 0"/>
  1073. <xsl:otherwise>
  1074. <xsl:value-of select="$text"/>
  1075. <xsl:call-template name="str:generate-string">
  1076. <xsl:with-param name="text" select="$text"/>
  1077. <xsl:with-param name="count" select="$count - 1"/>
  1078. </xsl:call-template>
  1079. </xsl:otherwise>
  1080. </xsl:choose>
  1081. </xsl:template>
  1082. </xsl:stylesheet>