pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

XML pastebin - collaborative debugging tool View Help


Posted by Keith Fahlgren on Mon 30 Jul 16:24
report spam | download | new post

  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>
  47. parent</literal>'s house -->
  48.     <xsl:variable name="sixth"   select='replace($fifth,    "&#x0027;s",                                   "&#x2019;s")'/>
  49.                                                             <!--  this was a real thing to be perpetuatin.' -->
  50.     <xsl:variable name="seventh" select='replace($sixth,    "([,.!a-zA-Z0-9])&#x0027;$",                   "$1&#x2019;")'/>
  51.                                                             <!--  this was a real thing to be perpetuatin'. -->
  52.     <xsl:variable name="eighth"  select='replace($seventh,  "(\s)&#x0027;([.a-zA-Z])",                  "$1&#x2018;$2")'/>
  53.                                                             <!--  !': dunno what is going on with this one... -->
  54.     <xsl:variable name="ninth"   select='replace($eighth,   "([,.!a-zA-Z0-9])&#x0027;([.:;&#x20;\t\n\r])", "$1&#x2019;$2")'/>
  55.  
  56.     <!-- Special cases'll get ya -->
  57.     <xsl:variable name="tenth"    select='replace($ninth,   "([a-zA-Z])&#x0027;([a-zA-Z])",  "$1&#x2019;$2")'/>
  58.                                                             <!-- in the '90s -->
  59.     <xsl:variable name="eleventh" select='replace($tenth,   "&#x0027;([0-9])",  "&#x2019;$1")'/>
  60.  
  61.     <!-- mixed -->
  62.                                                             <!-- nested: double-curl-open + ' -->
  63.     <xsl:variable name="twelfth" select='replace($eleventh,   "&#x201C;&#x0027;",  "&#x201C;&#x2018;")'/>
  64.                                                             <!-- nested: ' + double-curl-close -->
  65.     <xsl:variable name="thirteenth" select='replace($twelfth,   "&#x0027;&#x201D;",  "&#x2019;&#x201D;")'/>
  66.  
  67.     <!-- change this when you add more -->
  68.     <xsl:variable name="final"   select='$thirteenth'/>
  69.  
  70.     <xsl:value-of select="$final"/>
  71.   </xsl:template>
  72.  
  73. </xsl:stylesheet>

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me