Share Pastebin
Guest
Public paste!

Keith Fahlgren

By: a guest | Jul 30th, 2007 | Syntax: XML | Size: 4.45 KB | Hits: 96 | Expires: Never
Copy text to clipboard
  1. $ cat curlies.xsl
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  3.   <xsl:output method="xml" encoding="UTF-8"/>
  4.   <xsl:preserve-space elements="*"/>
  5.   <!-- Default Rule -->
  6.   <xsl:template match="@*|node()">
  7.     <xsl:copy>
  8.       <xsl:apply-templates select="@*|node()"/>
  9.     </xsl:copy>
  10.   </xsl:template>
  11.  
  12.   <xsl:template match="text()[not(
  13.                                  parent::command|
  14.                                  parent::computeroutput|
  15.                                  parent::constant|
  16.                                  parent::filename|
  17.                                  parent::function|
  18.                                  parent::literal|
  19.                                  parent::markup|
  20.                                  parent::option|
  21.                                  parent::optional|
  22.                                  parent::programlisting|
  23.                                  parent::prompt|
  24.                                  parent::replaceable|
  25.                                  parent::screen|
  26.                                  parent::sgmltag|
  27.                                  parent::userinput|
  28.                                  parent::varname
  29.                                  )]">
  30.     <xsl:variable name="input"   select="."/>                  
  31.  
  32.     <!-- doubles -->
  33.                                                             <!-- "Barring the baz... -->
  34.     <xsl:variable name="first"   select="replace($input,    '^&#x0022;(\S)',                     '&#x201C;$1')"/>
  35.  
  36.                                                             <!-- arring the baz." OR any other odd symbol at the end -->
  37.     <xsl:variable name="second"  select="replace($first,    '(\S)&#x0022;$',                   '$1&#x201D;')"/>
  38.                                                             <!--  "arring the baz OR preceded by opening parens, em dash, or CharMenuDelim -->
  39.     <xsl:variable name="third"   select="replace($second,   '([\s(&#x2014;&#x2192;])&#x0022;(\S)',                  '$1&#x201C;$2')"/>  <!-- ".022", for all you unbelievers -->
  40.                                                             <!--  fee," arring the baz OR followed by closing parens, em dash, or CharMenuDelim -->
  41.     <xsl:variable name="fourth"  select="replace($third,    '(\S)&#x0022;([,.:;?!&#x20;\t\n\r)&#x2014;&#x2192;])', '$1&#x201D;$2')"/>
  42.    
  43.     <!-- singles -->
  44.                                                             <!--  'Ole Bill was a big dog! -->
  45.     <xsl:variable name="fifth"   select='replace($fourth,   "^&#x0027;([.a-rt-zA-Z])",                     "&#x2018;$1")'/>
  46.                                                             <!-- <literal>parent</literal>'s house -->
  47.     <xsl:variable name="sixth"   select='replace($fifth,    "&#x0027;s",                                   "&#x2019;s")'/>
  48.                                                             <!--  this was a real thing to be perpetuatin.' -->
  49.     <xsl:variable name="seventh" select='replace($sixth,    "([,.!a-zA-Z0-9])&#x0027;$",                   "$1&#x2019;")'/>
  50.                                                             <!--  this was a real thing to be perpetuatin'. -->
  51.     <xsl:variable name="eighth"  select='replace($seventh,  "(\s)&#x0027;([.a-zA-Z])",                  "$1&#x2018;$2")'/>
  52.                                                             <!--  !': dunno what is going on with this one... -->
  53.     <xsl:variable name="ninth"   select='replace($eighth,   "([,.!a-zA-Z0-9])&#x0027;([.:;&#x20;\t\n\r])", "$1&#x2019;$2")'/>
  54.  
  55.     <!-- Special cases'll get ya -->
  56.     <xsl:variable name="tenth"    select='replace($ninth,   "([a-zA-Z])&#x0027;([a-zA-Z])",  "$1&#x2019;$2")'/>
  57.                                                             <!-- in the '90s -->
  58.     <xsl:variable name="eleventh" select='replace($tenth,   "&#x0027;([0-9])",  "&#x2019;$1")'/>
  59.  
  60.     <!-- mixed -->
  61.                                                             <!-- nested: double-curl-open + ' -->
  62.     <xsl:variable name="twelfth" select='replace($eleventh,   "&#x201C;&#x0027;",  "&#x201C;&#x2018;")'/>
  63.                                                             <!-- nested: ' + double-curl-close -->
  64.     <xsl:variable name="thirteenth" select='replace($twelfth,   "&#x0027;&#x201D;",  "&#x2019;&#x201D;")'/>
  65.  
  66.     <!-- change this when you add more -->
  67.     <xsl:variable name="final"   select='$thirteenth'/>
  68.  
  69.     <xsl:value-of select="$final"/>
  70.   </xsl:template>
  71.  
  72. </xsl:stylesheet>