]> git.nbdom.net Git - nb.git/commitdiff
etc/profile.d/functions
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 9 Mar 2019 23:14:22 +0000 (23:14 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 9 Mar 2019 23:14:22 +0000 (23:14 +0000)
etc/profile.d/functions
lib/xslt/xml2txt.xslt [new file with mode: 0644]

index cc00a9ba247069746d569a8614f3776df9ee420d..d34b3e76b37646b462d614b96ae653e74b20c349 100755 (executable)
@@ -779,74 +779,13 @@ html2pdf() {
        iconv -f utf-8 -t iso-8859-1 -c $@ | htmldoc --encryption --webpage --continuous --no-title --header '...' --footer '...' -
 }
 
+xml2txt() {
+       xsltproc $NB_ROOT/lib/xslt/xml2txt.xslt $@
+}
+
 xml2csv() {
        xsltproc $NB_ROOT/lib/xslt/xml2csv.xslt $@
 }
-# NB 16.01.18 csv2h() {
-# NB 16.01.18          shell_help "Usage: $FUNCNAME [PERL_REGEXP --sep|-s (default: tab)] [--noheader|-nh]" "$@" && return;
-# NB 16.01.18          local sep noheader;
-# NB 16.01.18          sep='\t';
-# NB 16.01.18          noheader=0;
-# NB 16.01.18          local files=''
-# NB 16.01.18 
-# NB 16.01.18          while [ $# -gt 0 ]; do
-# NB 16.01.18 
-# NB 16.01.18                  if [ -e "$1" ]; then
-# NB 16.01.18                          files="$files $1"
-# NB 16.01.18                          shift
-# NB 16.01.18                          continue
-# NB 16.01.18                  fi
-# NB 16.01.18 
-# NB 16.01.18                  case "$1" in
-# NB 16.01.18                          --sep|-s)
-# NB 16.01.18                                          sep=$2;
-# NB 16.01.18                                          shift
-# NB 16.01.18                          ;;
-# NB 16.01.18                          --noheader|-nh)
-# NB 16.01.18                                          noheader=1
-# NB 16.01.18                          ;;
-# NB 16.01.18                          *)
-# NB 16.01.18                                          echo "Unknow option: $1 at $0!";
-# NB 16.01.18                                          return 1
-# NB 16.01.18                          ;;
-# NB 16.01.18 
-# NB 16.01.18                  esac
-# NB 16.01.18 
-# NB 16.01.18                  shift
-# NB 16.01.18 
-# NB 16.01.18          done
-# NB 16.01.18 
-# NB 16.01.18          [ -z "$@" ] || sep="$@";
-# NB 16.01.18 
-# NB 16.01.18          cat $files | perl -MEncode -F"$sep" -ane 'BEGIN {
-# NB 16.01.18  $noheader = shift @ARGV;
-# NB 16.01.18  @len = (); @lines = (); 
-# NB 16.01.18  binmode( STDOUT, "utf8:" );
-# NB 16.01.18 };
-# NB 16.01.18 for ($i=0;$i<@F;$i++) {
-# NB 16.01.18  chomp($F[$i]);
-# NB 16.01.18  $F[$i] =~ s/^\r//;
-# NB 16.01.18  $F[$i] = Encode::decode_utf8($F[$i]);
-# NB 16.01.18  $len[$i] = $l if ( $l = length($F[$i])) >= $len[$i];
-# NB 16.01.18 }
-# NB 16.01.18 push @lines, [@F];
-# NB 16.01.18 END {
-# NB 16.01.18  exit unless @lines;
-# NB 16.01.18  $i = 0;
-# NB 16.01.18  $t = -1;
-# NB 16.01.18  $tot = @lines - ($noheader ? 0 : 1);
-# NB 16.01.18  $format = "| ".join(" | ",map {$t+=$_+3; "\%-".$_."s"} @len)." |".chr(10);
-# NB 16.01.18  $sep_line = "+".join("+",map {("-"x($_+2))} @len)."+".chr(10);
-# NB 16.01.18  print $sep_line;
-# NB 16.01.18  while ($_ = shift @lines) {
-# NB 16.01.18          printf $format,@$_;
-# NB 16.01.18          print $sep_line if !$noheader and !$i++;
-# NB 16.01.18  }
-# NB 16.01.18  print $sep_line;
-# NB 16.01.18  print "$tot Records\n";
-# NB 16.01.18 }
-# NB 16.01.18 ' $noheader
-# NB 16.01.18 }
 
 cron_d_install() {
        local usage fname file exp cron tmp test
diff --git a/lib/xslt/xml2txt.xslt b/lib/xslt/xml2txt.xslt
new file mode 100644 (file)
index 0000000..f8f5fce
--- /dev/null
@@ -0,0 +1,25 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+  <xsl:output method="text" encoding="utf-8" />
+
+  <xsl:param name="break" select="'&#xA;'" />
+  <xsl:param name="quote" select="''" />
+  <xsl:param name="delim" select="'&#009;'" />
+
+  <xsl:template match="/">
+    <xsl:apply-templates select="/*/*" />
+  </xsl:template>
+
+  <xsl:template match="/*/*">
+    <xsl:apply-templates />
+  </xsl:template>
+
+  <xsl:template match="*">
+    <!-- remove normalize-space() if you want keep white-space at it is --> 
+    <xsl:value-of select="concat($quote, name(), $quote)" />
+    <xsl:value-of select="$delim" />
+    <xsl:value-of select="concat($quote, normalize-space(), $quote)" />
+    <xsl:value-of select="$break" />
+  </xsl:template>
+
+  <xsl:template match="text()" />
+</xsl:stylesheet>