http://jsbeautifier.org/
This blog provides some ready-made tips, tricks, tweaks & interview questions-answers on C, C++, Perl, Shell Scripting and UNIX Commands.
Thursday, September 5, 2013
How do you transform XML into XHTML using XSLT?
1. Start with an XML document (books.xml).
2. Create an XSL stylesheet (books.xsl).
3. Keep both files at a specific location. Otherwise update the value of "href" tag with the absolute path of "books.xsl" in "books.xml".
4. Click the "books.xml" file to open in browser by default.
books.xml
--------------------------------------
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="books.xsl"?>
<catalog>
<book id="bk9781118013847">
<title>Beginning Perl</title>
<author>Curtis Ovid Poe</author>
<genre>Computer Programming</genre>
<publisher>Wiley / Wrox</publisher>
<price>31.99</price>
<publish_date>August 2012</publish_date>
<isbn>978-1-4571-2094-7</isbn>
<description>Perl's basics and best practices for Beginners</description>
</book>
<book id="bk9780596527242">
<title>Mastering Perl</title>
<author>Brian d Foy</author>
<genre>Computer Programming</genre>
<publisher>O'Reilly Media</publisher>
<price>31.99</price>
<publish_date>July 2007</publish_date>
<isbn>978-0-596-52724-2</isbn>
<description>Focuses on real-life problems of debugging, maintenance, configuration</description>
</book>
<book id="bk9780470556801">
<title>Perl and Apache</title>
<author>Adam McDaniel</author>
<genre>Computer Programming</genre>
<publisher>Wiley / Visual</publisher>
<price>34.99</price>
<publish_date>January 2011</publish_date>
<isbn>978-1-4571-3092-2</isbn>
<description>A visual blueprint for developing dynamic Web content</description>
</book>
</catalog>
books.xsl
--------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Book Details</h2>
<table border="1" style="width:70%;">
<tr bgcolor="#9acd32">
<th>Id</th>
<th>Title</th>
<th>Author</th>
<th>Price ($)</th>
<th>Publish Date</th>
<th>Genre</th>
<th>Description</th>
</tr>
<xsl:for-each select="catalog/book">
<xsl:sort select="@id"/>
<tr>
<td><xsl:value-of select="@id"/></td>
<td align="center"><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td>
<td align="right"><b><xsl:value-of select="price"/></b></td>
<td><xsl:value-of select="publish_date"/></td>
<td><xsl:value-of select="genre"/></td>
<td align="justify"><xsl:value-of select="description"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
2. Create an XSL stylesheet (books.xsl).
3. Keep both files at a specific location. Otherwise update the value of "href" tag with the absolute path of "books.xsl" in "books.xml".
4. Click the "books.xml" file to open in browser by default.
books.xml
--------------------------------------
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="books.xsl"?>
<catalog>
<book id="bk9781118013847">
<title>Beginning Perl</title>
<author>Curtis Ovid Poe</author>
<genre>Computer Programming</genre>
<publisher>Wiley / Wrox</publisher>
<price>31.99</price>
<publish_date>August 2012</publish_date>
<isbn>978-1-4571-2094-7</isbn>
<description>Perl's basics and best practices for Beginners</description>
</book>
<book id="bk9780596527242">
<title>Mastering Perl</title>
<author>Brian d Foy</author>
<genre>Computer Programming</genre>
<publisher>O'Reilly Media</publisher>
<price>31.99</price>
<publish_date>July 2007</publish_date>
<isbn>978-0-596-52724-2</isbn>
<description>Focuses on real-life problems of debugging, maintenance, configuration</description>
</book>
<book id="bk9780470556801">
<title>Perl and Apache</title>
<author>Adam McDaniel</author>
<genre>Computer Programming</genre>
<publisher>Wiley / Visual</publisher>
<price>34.99</price>
<publish_date>January 2011</publish_date>
<isbn>978-1-4571-3092-2</isbn>
<description>A visual blueprint for developing dynamic Web content</description>
</book>
</catalog>
books.xsl
--------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Book Details</h2>
<table border="1" style="width:70%;">
<tr bgcolor="#9acd32">
<th>Id</th>
<th>Title</th>
<th>Author</th>
<th>Price ($)</th>
<th>Publish Date</th>
<th>Genre</th>
<th>Description</th>
</tr>
<xsl:for-each select="catalog/book">
<xsl:sort select="@id"/>
<tr>
<td><xsl:value-of select="@id"/></td>
<td align="center"><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td>
<td align="right"><b><xsl:value-of select="price"/></b></td>
<td><xsl:value-of select="publish_date"/></td>
<td><xsl:value-of select="genre"/></td>
<td align="justify"><xsl:value-of select="description"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Monday, September 2, 2013
What is the use of %EXPORT_TAGS in Perl?
It is an associate array that specifies a way to access a list of symbols with tags.
Syntax:
%EXPORT_TAGS = (tag_name => [anonymous array/Array reference]);
For Example:
%EXPORT_TAGS = (
all => @EXPORT_OK
);
At the time of loading, use simply
use Module qw(:all); # instead of writing all the symbols
MyPerl.pm
---------------------------
package MyPerl;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(&Active);
our @EXPORT_OK = qw(&StrawBerry &IndigoStar);
our %EXPORT_TAGS = (
'Explicit' => \@EXPORT,
'Implicit' => \@EXPORT_OK,
'All' => [@EXPORT, @EXPORT_OK],
);
sub Active {
print "Active Perl\n";
}
sub StrawBerry {
print "StrawBerry Perl\n";
}
sub IndigoStar {
print "IndigoStar Perl\n";
}
1;
test.pl
---------------------
#!/usr/local/bin/perl
use MyPerl qw(:Explicit :Implicit);
#or
#use MyPerl qw(:All);
Active();
IndigoStar();
Syntax:
%EXPORT_TAGS = (tag_name => [anonymous array/Array reference]);
For Example:
%EXPORT_TAGS = (
all => @EXPORT_OK
);
At the time of loading, use simply
use Module qw(:all); # instead of writing all the symbols
MyPerl.pm
---------------------------
package MyPerl;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(&Active);
our @EXPORT_OK = qw(&StrawBerry &IndigoStar);
our %EXPORT_TAGS = (
'Explicit' => \@EXPORT,
'Implicit' => \@EXPORT_OK,
'All' => [@EXPORT, @EXPORT_OK],
);
sub Active {
print "Active Perl\n";
}
sub StrawBerry {
print "StrawBerry Perl\n";
}
sub IndigoStar {
print "IndigoStar Perl\n";
}
1;
test.pl
---------------------
#!/usr/local/bin/perl
use MyPerl qw(:Explicit :Implicit);
#or
#use MyPerl qw(:All);
Active();
IndigoStar();
Where do you get Perl binaries for MS Windows?
http://www.indigostar.com/
http://strawberryperl.com/
http://www.activestate.com/activeperl/downloads
http://strawberryperl.com/
http://www.activestate.com/activeperl/downloads
What are the side-effects of Taint mode in Perl?
When the taint mode ("-T") is in effect, the "." directory is removed from @INC, and the environment variables "PERL5LIB" and "PERLLIB" are ignored by Perl since they are obscured.
You can still adjust @INC from outside the program by using the "-I" command line option. The "-I" switch is clearly visible and therefore permitted.
Another way to modify @INC without modifying the program, is to use the "lib" pragma at command line.
perl -Mlib=/my/module_dir script.pl
Note that if a tainted string is added to @INC, the following problem will be reported:
"Insecure dependency in require while running with -T switch"
You can still adjust @INC from outside the program by using the "-I" command line option. The "-I" switch is clearly visible and therefore permitted.
Another way to modify @INC without modifying the program, is to use the "lib" pragma at command line.
perl -Mlib=/my/module_dir script.pl
Note that if a tainted string is added to @INC, the following problem will be reported:
"Insecure dependency in require while running with -T switch"
How can you restore original @INC in Perl?
When the lib module is first loaded, the current value of @INC is recorded in "@lib::ORIG_INC". To restore @INC to original value, you can use :
@INC = @lib::ORIG_INC;
@INC = @lib::ORIG_INC;
How can you remove the directories from @INC in Perl?
It can be achieved via "no lib".
e.g.
no lib "."; # removes cwd
no lib LIST; #removes directories defined in LIST
e.g.
no lib "."; # removes cwd
no lib LIST; #removes directories defined in LIST
What is the difference between "-Mlib" and "-I" option in Perl?
Theses are the ways to modify @INC without modifying the program.
The benefit of using "-Mlib=/my/module_dir" over "-I /my/module_dir" is the former automatically removes any duplicate directories while the later does not.
The benefit of using "-Mlib=/my/module_dir" over "-I /my/module_dir" is the former automatically removes any duplicate directories while the later does not.
Subscribe to:
Posts
(
Atom
)