XML

XML

в

| Java | Eclipse | UML |

XML and XSLT FAQ

в
XML

Perl script mapping.xsl.pl:

  1. #!/usr/bin/perl
  2. use strict;
  3.  
  4. my $root = "SomeRoot";
  5. my %rules;
  6. my $stripstart = "SomeStrippedRoot/";
  7.  
  8. while(<STDIN>) {
  9.     my ($x, $src, $dst);
  10.     ($x, $x, $x, $x, $src, $x, $dst) = split /,/;
  11.     $src =~ s/[\r\n]+$//;
  12.     $dst =~ s/[\r\n]+$//;
  13.     $src = $1 if $src =~ /^"(.*?)"$/;
  14.     $dst = $1 if $dst =~ /^"(.*?)"$/;
  15.     $src =~ s/""/"/g;
  16.     $dst =~ s/""/"/g;
  17.     $src = "/$src" unless $src =~ /^\//;
  18.     next unless $src && $dst;
  19.     next unless $src =~ /\//;
  20.     next unless $dst =~ /\//;
  21.     next unless $src =~ /^\/$root/;
  22.     #$src =~ s/\@/_at_/g;
  23.     #$src =~ s/=/_is_/g;
  24.     #$src =~ s/[^\w\/]/_/g;
  25.     $dst =~ s/^$stripstart// if defined $stripstart;
  26.     $rules{$src} = $dst;
  27. }
  28.  
  29. my $hier = {};
  30.  
  31. for (sort keys %rules) {
  32.     my ($src, $dst) = ($_, $rules{$_});
  33.     $src =~ s/^\///;
  34.     my @path = split(/\//, $src);
  35.     my $branch = $hier;
  36.     for my $i (0 .. $#path - 1) {
  37.         my $sub = $path[$i];
  38.         $branch->{$sub} = {} unless defined $branch->{$sub};
  39.         $branch = $branch->{$sub};
  40.     }
  41.     $branch->{$#path} = $dst;
  42. }
  43.  
  44. traverse(0, $hier);
  45.  
  46. sub traverse
  47. {
  48.     my ($indent, $branch) = @_;
  49.     my $white = "\t" x $indent;
  50.     for my $key (sort keys %$branch) {
  51.         my $val = $branch->{$key};
  52.         if (ref $val) {
  53.             my $open = $key;
  54.             (my $close = $open) =~ s/\[.*$//;
  55.             print "$white<$open>\n";
  56.             traverse($indent + 1, $val);
  57.             print "$white</$close>\n";
  58.         } else {
  59.             print "$white<xsl:value-of select=\"$val\"/>\n";
  60.         }
  61.     }
  62. }

I'm trying to get rid of the ' and the line feeds in my string but can't get it to work.The first translation of line feeds works just fine, but I can't get rid of the apostrophe.The parser gives me an error because of the &apos.
You need to quote using xml entity references in order to put in an XML attribute:

<xsl:value-of select="translate(translate(/node,'&#10;',''),&quot;'&quot;, '')"/>

Although you can remove both characters at once with

<xsl:value-of select="translate(/node,&quot;&#10;'&quot;,'')"/>
RSS-материал