My Four
Preferences
My Four
  Preferences
in my Perl Web practice
Architecture and music
Danube
My Four
  Preferences
in my Perl Web practice
1. Parsing URLs with grammar
2. .ini configuration files
3. WWW::Page
4. XSLT
0.
Perl 5.10
1.
Parsing URLs with grammar
URL is . . .
URL is . . .
a string
URL is . . .
a string,
a set of parts
URL is . . .
a string,
a set of parts,
a container of parameters
Blog URL scheme
Blog URL scheme
/
Blog URL scheme
/
/message‐uri/
Blog URL scheme
/
/message‐uri/
/tag/tag‐name/
Blog URL scheme
/
/message‐uri/
/tag/tag‐name/
/post/
Blog URL scheme
/
/message‐uri/
/tag/tag‐name/
/post/
/message‐uri/post/
Blog URL scheme
/
/message‐uri/
/tag/tag‐name/
/post/
/message‐uri/post/
/message‐uri/comments/
How to parse?
How to parse?
RewriteRules in .htaccess
How to parse?
RewriteRules in .htaccess
^$ /index.pl?page=home
How to parse?
RewriteRules in .htaccess
^$ /index.pl?page=home
^post/?$ /post.pl
How to parse?
RewriteRules in .htaccess
^$ /index.pl?page=home
^post/?$ /post.pl
^([^/]+)/? /index.pl?page=$1
How to parse?
RewriteRules in .htaccess
^$ /index.pl?page=home
^post/?$ /post.pl
^([^/]+)/? /index.pl?page=$1
etc.
How to parse?
RewriteRules in .htaccess

Bad: involves programming
outside Perl
How to parse?
Regular expressions
How to parse?
Regular expressions
given ($uri) {
   when (/^/$/) {...}
}
How to parse?
Regular expressions
given ($uri) {
   when (/^/$/) {...}
   when (/^/post/?/) {...}
}
How to parse?
Regular expressions
given ($uri) {
   when (/^/$/) {...}
   when (/^/post/?/) {...}
   # (regexes as in .hta...
How to parse?
Regular expressions

Bad: rules are not obvious
How to parse?
split builtin
How to parse?
split builtin
@parts = split m{/}, $uri;
given (scalar @parts) {
   when (1) {...}
   when (2) {...}
}
How to parse?
split builtin

Bad: boring
How to parse?
Grammars
How to parse?
Grammars

Cool!
How to parse?
Grammars

Cool!
Easy to maintain
How to parse?
Grammars

Cool!
Easy to maintain
But might be slow
How to parse?
Grammars

Cool!
Easy to maintain
But might be slow . . .
up to 100 times over regexes.
Gramars

Parse::RecDescent
today

Perl 6 grammars
tomorrow
Gramars

Parse::RecDescent
today

Perl 6 grammars
after Christmas
uri          : post EOL
             | view EOL
uri          : post EOL
             | view EOL
post         : post‐message
             | post‐comment
uri          : post EOL
             | view EOL
post         : post‐message
             | post‐comment
view         : vie...
uri          : post EOL
             | view EOL
post         : post‐message
             | post‐comment
view         : vie...
uri          : post EOL
             | view EOL
post         : post‐message
             | post‐comment
view         : vie...
uri          : post EOL
             | view EOL
post         : post‐message
             | post‐comment
view         : vie...
uri          : post EOL
             | view EOL
post         : post‐message
             | post‐comment
view         : vie...
uri          : post EOL
             | view EOL
post         : post‐message
             | post‐comment
view         : vie...
Actions in grammars
uri : post EOL
    | view EOL
uri : post EOL {
         $action = ‘post’;
      }
    | view EOL
uri : post EOL {
         $action = ‘post’;
      }
    | view EOL {
         $action = ‘view’;
      }
view‐message : ‘/’ word ‘/’
view‐tag     : ‘/tag/’ word ‘/’
view‐message : ‘/’ word ‘/’ {
                  $msg_sid = $item{word};
               }
view‐tag     : ‘/tag/’ word ‘/’
view‐message : ‘/’ word ‘/’ {
                  $msg_sid = $item{word};
               }
view‐tag     : ‘/tag/’ word ‘/’ {...
http://example.com/twincity/


$action = ‘view’;
$msg_sid = ‘twincity’;
http://example.com/twincity/


$action = ‘view’;
$msg_sid = ‘twincity’;



http://example.com/tag/workshop/


$action = ‘v...
my %uri = (
    '/'              => {
                       'type' => 'index',
                     },
    '/alpha/'     ...
for $uri (keys %uri) {    
    $parser‐>parse($uri);


    cmp_deeply(
        $parser‐>{data},
        $uri{$uri},
      ...
Grammars are

logical
Grammars are

logical,

easy to extend
Grammars are

logical,

easy to extend,

cacheable
Grammars are

logical,

easy to extend,

cacheable,

easy to test
2.
.ini configuration files
Application =
code + configuration
Example: blog


number of messages per page
#!/usr/bin/perl
my $MSG_PER_PAGE = 10;
#!/usr/bin/perl
my $MSG_PER_PAGE = 10;
Load configuration
from external file
Load configuration
from external non-Perl file
<config>
   <page_length>10</page_length>
</config>
Question:
   XML
    or
  JSON
    or
  YAML
    ?
Answer:
Windows INI
[page]
length=10
[section]
page_length=10


[thread]
page_length=10


[obsene]
replacement=***


[preview]
last_posts=31
last_message_lengt...
global.ini   local.ini
global.ini    local.ini

[page]
length=10


[db]          [db]
host=db.int   host=localhost
port=3333     port=3306
use Config::INI::Access;


config‐>load(quot;conf/config.iniquot;);
use Config::INI::Access;


config‐>load(quot;conf/config.iniquot;);
config‐>load(quot;conf/local.iniquot;);
use Config::INI::Access;


config‐>load(quot;conf/config.iniquot;);
config‐>load(quot;conf/local.iniquot;);


say config‐>...
[db]
host=localhost
port=3306



say config‐>db‐>host;
3.
WWW::Page
WWW::Page
is a kinda MVC
http://example.com/some/page
http://example.com/some/page


/www/example.com/some/page/index.xml
http://example.com/some/page


/www/example.com/some/page/index.xml


              XML
http://example.com/some/page


/www/example.com/some/page/index.xml


               XML
        Perl
               XML
http://example.com/some/page


/www/example.com/some/page/index.xml


               XML
        Perl
               XML
 ...
http://example.com/some/page


/www/example.com/some/page/index.xml


                XML
        Perl
                XML...
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
    use WWW::Page;
    use encoding 'utf‐8';


    my $page = new WWW::Page ({
        'xslt‐root'       => quot;../data/x...
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
            sub Import::Client::keywordList
        t...
   package Import::Client;

   sub keywordList
   {
       my ($this, $page, $node, $args) = @_;
   
       my $sth = $dbh...
   package Import::Client;

   sub keywordList
   {
       my ($this, $page, $node, $args) = @_;
   
       my $sth = $dbh...
   package Import::Client;

   sub keywordList
   {
       my ($this, $page, $node, $args) = @_;
   
       my $sth = $dbh...
   package Import::Client;

   sub keywordList
   {
       my ($this, $page, $node, $args) = @_;
   
       my $sth = $dbh...
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
<keyword‐list>
    <item uri=quot;http://perl.org/quot;>Perl</item>
    <item uri=quot;http://dev.perl.org/quot;>Perl 6</i...
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
XML
XSLT
        HTML


       Browser
Possible improvements
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
4.
XSLT
Not .WHAT XSLT is
but .WHY I use it
4a.
XSLT: divide and power
website =
 logic    +   layout
website =
Perl-code +   HTML
website =
Perl-code +   XML+XSLT
website =
Perl-code +       XML+XSLT


Perl programmer    XSLT coder
website =
Perl-code +       XML+XSLT


Perl programmer    XSLT coder
4b.
XSLT: multiple languages
en.xml 


<strings>
    <months>
       <item>January</item>
       <item>February</item>
          . . .
       <item>Dec...
de.xml 


<strings>
    <months>
       <item>Januar</item>
       <item>Februar</item>
          . . .
       <item>Dezem...
at.xml 


<strings>
    <months>
       <item>Jänner</item>
       <item>Februar</item>
          . . .
       <item>Dezem...
<xsl:variable name=quot;strquot;>
    <xsl:copy‐of select=quot;
       document(
          concat($lang, ‘.xml’)
       )q...
<xsl:variable name=quot;strquot;>
    <xsl:copy‐of select=quot;
       document(
          concat($lang, ‘.xml’)
       )/...
<date day=quot;7quot; month=quot;11quot; year=quot;2008quot;/>
<date day=quot;7quot; month=quot;11quot; year=quot;2008quot;/>




<xsl:value‐of select=quot;@dayquot;/>
<date day=quot;7quot; month=quot;11quot; year=quot;2008quot;/>




<xsl:value‐of select=quot;@yearquot;/>
<date day=quot;7quot; month=quot;11quot; year=quot;2008quot;/>




<xsl:value‐of 
    select=quot;$str/months/item[@month]...
4b.
XSLT: multiple layouts
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
    <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>
    <page
        import=quot;Import::Clientquot;
        trans...
website =
Perl-code +       XML+XSLT


Perl programmer    XSLT coder
website =
Perl-code +       XML+XSLT


Perl programmer    XSLT coder
                   XSLT coder
                   XSLT...
__END__

Andrew Shitov

http://andy.sh | mail@andy.sh
My four preferences in Perl Web practices
My four preferences in Perl Web practices
My four preferences in Perl Web practices
My four preferences in Perl Web practices
My four preferences in Perl Web practices
My four preferences in Perl Web practices
My four preferences in Perl Web practices
My four preferences in Perl Web practices
My four preferences in Perl Web practices
Upcoming SlideShare
Loading in …5
×

My four preferences in Perl Web practices

922 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
922
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

My four preferences in Perl Web practices

  1. 1. My Four Preferences
  2. 2. My Four Preferences in my Perl Web practice
  3. 3. Architecture and music
  4. 4. Danube
  5. 5. My Four Preferences in my Perl Web practice
  6. 6. 1. Parsing URLs with grammar 2. .ini configuration files 3. WWW::Page 4. XSLT
  7. 7. 0. Perl 5.10
  8. 8. 1. Parsing URLs with grammar
  9. 9. URL is . . .
  10. 10. URL is . . . a string
  11. 11. URL is . . . a string, a set of parts
  12. 12. URL is . . . a string, a set of parts, a container of parameters
  13. 13. Blog URL scheme
  14. 14. Blog URL scheme /
  15. 15. Blog URL scheme / /message‐uri/
  16. 16. Blog URL scheme / /message‐uri/ /tag/tag‐name/
  17. 17. Blog URL scheme / /message‐uri/ /tag/tag‐name/ /post/
  18. 18. Blog URL scheme / /message‐uri/ /tag/tag‐name/ /post/ /message‐uri/post/
  19. 19. Blog URL scheme / /message‐uri/ /tag/tag‐name/ /post/ /message‐uri/post/ /message‐uri/comments/
  20. 20. How to parse?
  21. 21. How to parse? RewriteRules in .htaccess
  22. 22. How to parse? RewriteRules in .htaccess ^$ /index.pl?page=home
  23. 23. How to parse? RewriteRules in .htaccess ^$ /index.pl?page=home ^post/?$ /post.pl
  24. 24. How to parse? RewriteRules in .htaccess ^$ /index.pl?page=home ^post/?$ /post.pl ^([^/]+)/? /index.pl?page=$1
  25. 25. How to parse? RewriteRules in .htaccess ^$ /index.pl?page=home ^post/?$ /post.pl ^([^/]+)/? /index.pl?page=$1 etc.
  26. 26. How to parse? RewriteRules in .htaccess Bad: involves programming outside Perl
  27. 27. How to parse? Regular expressions
  28. 28. How to parse? Regular expressions given ($uri) {    when (/^/$/) {...} }
  29. 29. How to parse? Regular expressions given ($uri) {    when (/^/$/) {...}    when (/^/post/?/) {...} }
  30. 30. How to parse? Regular expressions given ($uri) {    when (/^/$/) {...}    when (/^/post/?/) {...}    # (regexes as in .htaccess) }
  31. 31. How to parse? Regular expressions Bad: rules are not obvious
  32. 32. How to parse? split builtin
  33. 33. How to parse? split builtin @parts = split m{/}, $uri; given (scalar @parts) {    when (1) {...}    when (2) {...} }
  34. 34. How to parse? split builtin Bad: boring
  35. 35. How to parse? Grammars
  36. 36. How to parse? Grammars Cool!
  37. 37. How to parse? Grammars Cool! Easy to maintain
  38. 38. How to parse? Grammars Cool! Easy to maintain But might be slow
  39. 39. How to parse? Grammars Cool! Easy to maintain But might be slow . . . up to 100 times over regexes.
  40. 40. Gramars Parse::RecDescent today Perl 6 grammars tomorrow
  41. 41. Gramars Parse::RecDescent today Perl 6 grammars after Christmas
  42. 42. uri          : post EOL              | view EOL
  43. 43. uri          : post EOL              | view EOL post         : post‐message              | post‐comment
  44. 44. uri          : post EOL              | view EOL post         : post‐message              | post‐comment view         : view‐message              | view‐tag
  45. 45. uri          : post EOL              | view EOL post         : post‐message              | post‐comment view         : view‐message              | view‐tag view‐message : ‘/’ word ‘/’
  46. 46. uri          : post EOL              | view EOL post         : post‐message              | post‐comment view         : view‐message              | view‐tag view‐message : ‘/’ word ‘/’ view‐tag     : ‘/tag/’ word ‘/’
  47. 47. uri          : post EOL              | view EOL post         : post‐message              | post‐comment view         : view‐message              | view‐tag view‐message : ‘/’ word ‘/’ view‐tag     : ‘/tag/’ word ‘/’ word         : /w+/
  48. 48. uri          : post EOL              | view EOL post         : post‐message              | post‐comment view         : view‐message              | view‐tag view‐message : ‘/’ word ‘/’ view‐tag     : ‘/tag/’ word ‘/’ word         : /w+/ post‐message : ‘/post/’
  49. 49. uri          : post EOL              | view EOL post         : post‐message              | post‐comment view         : view‐message              | view‐tag view‐message : ‘/’ word ‘/’ view‐tag     : ‘/tag/’ word ‘/’ word         : /w+/ post‐message : ‘/post/’ post‐comment : view‐message ‘/post/’
  50. 50. Actions in grammars
  51. 51. uri : post EOL     | view EOL
  52. 52. uri : post EOL {          $action = ‘post’;       }     | view EOL
  53. 53. uri : post EOL {          $action = ‘post’;       }     | view EOL {          $action = ‘view’;       }
  54. 54. view‐message : ‘/’ word ‘/’ view‐tag     : ‘/tag/’ word ‘/’
  55. 55. view‐message : ‘/’ word ‘/’ {                   $msg_sid = $item{word};                } view‐tag     : ‘/tag/’ word ‘/’
  56. 56. view‐message : ‘/’ word ‘/’ {                   $msg_sid = $item{word};                } view‐tag     : ‘/tag/’ word ‘/’ {                   $action = ‘view‐tag’;                   $tag = $item{word};                }
  57. 57. http://example.com/twincity/ $action = ‘view’; $msg_sid = ‘twincity’;
  58. 58. http://example.com/twincity/ $action = ‘view’; $msg_sid = ‘twincity’; http://example.com/tag/workshop/ $action = ‘view‐tag’; $tag = ‘workshop’;
  59. 59. my %uri = (     '/'              => {                        'type' => 'index',                      },     '/alpha/'        => {                        'type' => 'section',                        'sectionUri' => 'alpha',                        'sectionPage' => 1,                      },     '/beta‐2/34/14/' => {                        'type' => 'message',                        'sectionUri' => 'beta',                        'sectionPage' => 2,                        'threadID' => 34,                        'threadPage' => 1,                        'messageID' => 14,                      },     '/‐/'            => {                        'type' => '404',                      });
  60. 60. for $uri (keys %uri) {         $parser‐>parse($uri);     cmp_deeply(         $parser‐>{data},         $uri{$uri},         $uri     ); }
  61. 61. Grammars are logical
  62. 62. Grammars are logical, easy to extend
  63. 63. Grammars are logical, easy to extend, cacheable
  64. 64. Grammars are logical, easy to extend, cacheable, easy to test
  65. 65. 2. .ini configuration files
  66. 66. Application = code + configuration
  67. 67. Example: blog number of messages per page
  68. 68. #!/usr/bin/perl my $MSG_PER_PAGE = 10;
  69. 69. #!/usr/bin/perl my $MSG_PER_PAGE = 10;
  70. 70. Load configuration from external file
  71. 71. Load configuration from external non-Perl file
  72. 72. <config>    <page_length>10</page_length> </config>
  73. 73. Question: XML or JSON or YAML ?
  74. 74. Answer: Windows INI
  75. 75. [page] length=10
  76. 76. [section] page_length=10 [thread] page_length=10 [obsene] replacement=*** [preview] last_posts=31 last_message_length=200
  77. 77. global.ini local.ini
  78. 78. global.ini local.ini [page] length=10 [db] [db] host=db.int host=localhost port=3333 port=3306
  79. 79. use Config::INI::Access; config‐>load(quot;conf/config.iniquot;);
  80. 80. use Config::INI::Access; config‐>load(quot;conf/config.iniquot;); config‐>load(quot;conf/local.iniquot;);
  81. 81. use Config::INI::Access; config‐>load(quot;conf/config.iniquot;); config‐>load(quot;conf/local.iniquot;); say config‐>db‐>host;
  82. 82. [db] host=localhost port=3306 say config‐>db‐>host;
  83. 83. 3. WWW::Page
  84. 84. WWW::Page is a kinda MVC
  85. 85. http://example.com/some/page
  86. 86. http://example.com/some/page /www/example.com/some/page/index.xml
  87. 87. http://example.com/some/page /www/example.com/some/page/index.xml XML
  88. 88. http://example.com/some/page /www/example.com/some/page/index.xml XML Perl XML
  89. 89. http://example.com/some/page /www/example.com/some/page/index.xml XML Perl XML XSLT HTML
  90. 90. http://example.com/some/page /www/example.com/some/page/index.xml XML Perl XML XSLT HTML Browser
  91. 91.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <title>WWW::Page Web‐Site</title>             <locale>en‐gb</locale>             <page:keyword‐list/>         </manifest>              <content>             <page:month‐calendar/>         </content>     </page>
  92. 92.     use WWW::Page;     use encoding 'utf‐8';     my $page = new WWW::Page ({         'xslt‐root'       => quot;../data/xslquot;,     });     print $page‐>as_string();
  93. 93.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <title>WWW::Page Web‐Site</title>             <locale>en‐gb</locale>             <page:keyword‐list/>         </manifest>              <content>             <page:month‐calendar/>         </content>     </page>
  94. 94.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <title>WWW::Page Web‐Site</title>             <locale>en‐gb</locale>             <page:keyword‐list/>         </manifest>              <content>             <page:month‐calendar/>         </content>     </page>
  95. 95.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page             sub Import::Client::keywordList         transform=quot;view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <title>WWW::Page Web‐Site</title>             <locale>en‐gb</locale>             <page:keyword‐list/>         </manifest>              <content>             <page:month‐calendar/>         </content>     </page>
  96. 96.    package Import::Client;    sub keywordList    {        my ($this, $page, $node, $args) = @_;            my $sth = $dbh‐>prepare(            quot;select keyword, uri from keywordsquot;);        $sth‐>execute();        while (my ($keyword, $uri) = $sth‐>fetchrow_array())        {            my $item =                 $page‐>{'xml'}‐>createElement ('item');            $item‐>appendText($keyword);            $item‐>setAttribute('uri', $uri);            $node‐>appendChild($item);        }            return $node;    }
  97. 97.    package Import::Client;    sub keywordList    {        my ($this, $page, $node, $args) = @_;            my $sth = $dbh‐>prepare(            quot;select keyword, uri from keywordsquot;);        $sth‐>execute();        while (my ($keyword, $uri) = $sth‐>fetchrow_array())        {            my $item =                 $page‐>{'xml'}‐>createElement ('item');            $item‐>appendText($keyword);            $item‐>setAttribute('uri', $uri);            $node‐>appendChild($item);        }            return $node;    }
  98. 98.    package Import::Client;    sub keywordList    {        my ($this, $page, $node, $args) = @_;            my $sth = $dbh‐>prepare(            quot;select keyword, uri from keywordsquot;);        $sth‐>execute();        while (my ($keyword, $uri) = $sth‐>fetchrow_array())        {            my $item =                 $page‐>{'xml'}‐>createElement ('item');            $item‐>appendText($keyword);            $item‐>setAttribute('uri', $uri);            $node‐>appendChild($item);        }            return $node;    }
  99. 99.    package Import::Client;    sub keywordList    {        my ($this, $page, $node, $args) = @_;            my $sth = $dbh‐>prepare(            quot;select keyword, uri from keywordsquot;);        $sth‐>execute();        while (my ($keyword, $uri) = $sth‐>fetchrow_array())        {            my $item =                 $page‐>{'xml'}‐>createElement ('item');            $item‐>appendText($keyword);            $item‐>setAttribute('uri', $uri);            $node‐>appendChild($item);        }            return $node;    }
  100. 100.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <title>WWW::Page Web‐Site</title>             <locale>en‐gb</locale>             <page:keyword‐list/>         </manifest>              <content>             <page:month‐calendar/>         </content>     </page>
  101. 101.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <title>WWW::Page Web‐Site</title>             <locale>en‐gb</locale>             <page:keyword‐list/>         </manifest>              <content>             <page:month‐calendar/>         </content>     </page>
  102. 102. <keyword‐list>     <item uri=quot;http://perl.org/quot;>Perl</item>     <item uri=quot;http://dev.perl.org/quot;>Perl 6</item>     <item uri=quot;http://bbc.co.uk/quot;>Perl on rails</item> </keyword‐list>
  103. 103.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <title>WWW::Page Web‐Site</title>             <locale>en‐gb</locale>             <keyword‐list> . . . </keyword‐list>         </manifest>              <content>             <month‐calendar> . . . </month‐calendar>         </content>     </page>
  104. 104. XML XSLT HTML Browser
  105. 105. Possible improvements
  106. 106.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <page:keyword‐list remote=quot;host2quot;>         </manifest>              <content>             <page:month‐calendar/>         </content>     </page>
  107. 107.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <page:keyword‐list remote=quot;host2quot;>         </manifest>              <content>             <page:month‐calendar cache=quot;memcachedquot;/>         </content>     </page>
  108. 108.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <page:keyword‐list remote=quot;host2quot;>         </manifest>              <content>             <page:month‐calendar cache=quot;xmlquot;/>         </content>     </page>
  109. 109.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <page:keyword‐list remote=quot;host2quot;>         </manifest>              <content>             <page:month‐calendar transform=quot;other.xslquot;/>         </content>     </page>
  110. 110. 4. XSLT
  111. 111. Not .WHAT XSLT is but .WHY I use it
  112. 112. 4a. XSLT: divide and power
  113. 113. website = logic + layout
  114. 114. website = Perl-code + HTML
  115. 115. website = Perl-code + XML+XSLT
  116. 116. website = Perl-code + XML+XSLT Perl programmer XSLT coder
  117. 117. website = Perl-code + XML+XSLT Perl programmer XSLT coder
  118. 118. 4b. XSLT: multiple languages
  119. 119. en.xml  <strings>     <months>        <item>January</item>        <item>February</item>           . . .        <item>December</item>     </months> </strings>
  120. 120. de.xml  <strings>     <months>        <item>Januar</item>        <item>Februar</item>           . . .        <item>Dezember</item>     </months> </strings>
  121. 121. at.xml  <strings>     <months>        <item>Jänner</item>        <item>Februar</item>           . . .        <item>Dezember</item>     </months> </strings>
  122. 122. <xsl:variable name=quot;strquot;>     <xsl:copy‐of select=quot;        document(           concat($lang, ‘.xml’)        )quot;/> </xsl:variable>
  123. 123. <xsl:variable name=quot;strquot;>     <xsl:copy‐of select=quot;        document(           concat($lang, ‘.xml’)        )/stringsquot;/> </xsl:variable>
  124. 124. <date day=quot;7quot; month=quot;11quot; year=quot;2008quot;/>
  125. 125. <date day=quot;7quot; month=quot;11quot; year=quot;2008quot;/> <xsl:value‐of select=quot;@dayquot;/>
  126. 126. <date day=quot;7quot; month=quot;11quot; year=quot;2008quot;/> <xsl:value‐of select=quot;@yearquot;/>
  127. 127. <date day=quot;7quot; month=quot;11quot; year=quot;2008quot;/> <xsl:value‐of      select=quot;$str/months/item[@month]quot;/>
  128. 128. 4b. XSLT: multiple layouts
  129. 129.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <title>WWW::Page Web‐Site</title>             <locale>en‐gb</locale>             <page:keyword‐list/>         </manifest>              <content>             <page:month‐calendar/>         </content>     </page>
  130. 130.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;pda/view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <title>WWW::Page Web‐Site</title>             <locale>en‐gb</locale>             <page:keyword‐list/>         </manifest>              <content>             <page:month‐calendar/>         </content>     </page>
  131. 131.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;iphone/view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <title>WWW::Page Web‐Site</title>             <locale>en‐gb</locale>             <page:keyword‐list/>         </manifest>              <content>             <page:month‐calendar/>         </content>     </page>
  132. 132.     <?xml version=quot;1.0quot; encoding=quot;UTF‐8quot;?>     <page         import=quot;Import::Clientquot;         transform=quot;rss/view.xslquot;         xmlns:page=quot;urn:www‐pagequot;>              <manifest>             <title>WWW::Page Web‐Site</title>             <locale>en‐gb</locale>             <page:keyword‐list/>         </manifest>              <content>             <page:month‐calendar/>         </content>     </page>
  133. 133. website = Perl-code + XML+XSLT Perl programmer XSLT coder
  134. 134. website = Perl-code + XML+XSLT Perl programmer XSLT coder XSLT coder XSLT coder XSLT coder
  135. 135. __END__ Andrew Shitov http://andy.sh | mail@andy.sh

×