2011年10月17日月曜日

[CP:AMA] 2 C Fundamentals

Chapter 2: Programing Projects

1.
#include <stdio.h>

int main(void)
{
printf(" *\n");
printf(" *\n");
printf(" *\n");
printf("* *\n");
printf(" * *\n");
printf(" *\n");

return 0;
}


2.
#include <stdio.h>

#define PI 3.14f
#define COEFFICIENT (4.0f / 3.0f)

int main(void)
{
float volume = 0, radius = 0;

printf("Enter the radius of your sphere:");
scanf("%f", &radius);

volume = COEFFICIENT * PI * radius * radius * radius;

printf("The volume of the sphere: %.2f\n", volume);

return 0;
}


4.
#include <stdio.h>

int main(void)
{
float amount = 0;

printf("Enter an amount: ");
scanf("%f", &amount);

printf("With tax added: %0.2f\n", amount * 1.05f);

return 0;
}


5.
#include <stdio.h>

int main(void)
{
float x = 0;

printf("Enter x: ");
scanf("%f", &x);

printf("The answer: %0.2f\n",
3 * x * x * x * x *x +
2 * x * x * x * x -
5 * x * x * x -
x * x +
7 * x -
6);

return 0;
}


6.
#include <stdio.h>

int main(void)
{
float x = 0;

printf("Enter x: ");
scanf("%f", &x);

printf("The answer: %0.2f\n",
((((3 * x + 2) - 5) * x - 1) * x + 7) * x - 6);

return 0;
}


7.
#include <stdio.h>

int main(void)
{
int amount = 0;
int bills20 = 0, bills10 = 0, bills05 = 0, bills01 = 0;

printf("enter a dollar amount: ");
scanf("%d", &amount);

bills20 = amount / 20;
bills10 = (amount - bills20 * 20) / 10;
bills05 = (amount - bills20 * 20 -bills10 * 10) / 5;
bills01 = amount - bills20 * 20 -bills10 * 10 - bills05 * 05;

printf("$20 bills: %d\n", bills20);
printf("$10 bills: %d\n", bills10);
printf(" $5 bills: %d\n", bills05);
printf(" $1 bills: %d\n", bills01);

return 0;
}


8.
#include <stdio.h>

int main(void)
{
float amount_of_loan = 0.0f;
float interest_rate = 0.0f;
float monthly_payment = 0.0f;
float balance_after_first_payment = 0.0f, balance_after_second_payment = 0.0f, balance_after_third_payment = 0.0f;
float monthly_interest_rate = 0.0f;

printf("Enter amount of loan: ");
scanf("%f", &amount_of_loan);
printf("Enter interest rate: ");
scanf("%f", &interest_rate);
printf("Enter monthly payment: ");
scanf("%f", &monthly_payment);

monthly_interest_rate = interest_rate / (100.0f * 12.0f);

amount_of_loan = (amount_of_loan) * (1.0f + monthly_interest_rate);
balance_after_first_payment = amount_of_loan - monthly_payment;
amount_of_loan = (amount_of_loan - monthly_payment) * (1.0f + monthly_interest_rate);
balance_after_second_payment = amount_of_loan - monthly_payment;
amount_of_loan = (amount_of_loan - monthly_payment) * (1.0f + monthly_interest_rate);
balance_after_third_payment = amount_of_loan - monthly_payment;

printf("Balance remaining after first payment: %.2f\n", balance_after_first_payment);
printf("Balance remaining after second payment: %.2f\n", balance_after_second_payment);
printf("Balance remaining after third payment: %.2f\n", balance_after_third_payment);

return 0;
}

2011年5月3日火曜日

[XML VQG] 2. XSLT (10)

I gave up to follow the examples in the book one by one. So this example is the last one, and covers all the features regarding XSLT that explained in the chapter 2.

Here's the list of additional features.

  • xsl:sort

  • xsl:choose

  • xsl:template

  • xsl:apply-templates




$ cat vcard-rdf-sample.xml
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:v="http://www.w3.org/2006/vcard/ns#">

<v:VCard rdf:about = "http://example.com/me/corky" >
<v:n>Corky Crystal</v:n>
<v:fn>Corky Crystal</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Corky</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Corky</v:sort-string>
<v:x-phonetic-first-name>Corky</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Crystal</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 5555 5555</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:corky@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>111 Lake Drive</v:street-address>
<v:locality>WonderCity</v:locality>
<v:postal-code>5555</v:postal-code>
<v:country-name>Australia</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
<v:VCard rdf:about = "http://example.com/me/al" >
<v:n>Al Pacino</v:n>
<v:fn>Al Pacino</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Al</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Al</v:sort-string>
<v:x-phonetic-first-name>Al</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Pacino</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 6666 6666</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Work"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:al@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>301 West 57th Street, 16C</v:street-address>
<v:locality>New York</v:locality>
<v:region>New York</v:region>
<v:postal-code>10017</v:postal-code>
<v:country-name>USA</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
<v:VCard rdf:about = "http://example.com/me/ethan" >
<v:n>Ethan Hawke</v:n>
<v:fn>Ethan Hawke</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Ethan</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Ethan</v:sort-string>
<v:x-phonetic-first-name>Ethan</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Hawke</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 7777 7777</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:ethan@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>c/o 1775 Broadway 701</v:street-address>
<v:locality>New York</v:locality>
<v:region>New York</v:region>
<v:postal-code>10019</v:postal-code>
<v:country-name>USA</v:country-name>
</rdf:Description>
</v:adr>
</v:VCard>
<v:VCard rdf:about = "http://example.com/me/brad" >
<v:n>Brad Pitt</v:n>
<v:fn>Brad Pitt</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Brad</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Brad</v:sort-string>
<v:x-phonetic-first-name>Brad</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Pitt</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 8888 8888</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Work"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:brad@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>9150 Wilshire Boulevard Suite 350</v:street-address>
<v:locality>Beverly Hills</v:locality>
<v:region>California</v:region>
<v:postal-code>90212</v:postal-code>
<v:country-name>USA</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Work"/>
</rdf:Description>
</v:adr>
</v:VCard>
</rdf:RDF>


$ cat xslt-sample.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:v="http://www.w3.org/2006/vcard/ns#"
version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html><head><title>Addresses of VIP</title></head>
<body>
<h1>Addresses of Five VIPs</h1>
<table border="1"><tr><th>Name</th><th>Country</th><th>Tel</th></tr>

<xsl:for-each select="rdf:RDF/v:VCard">
<xsl:sort select="v:sort-string" order="descending" data-type="text"/>
<tr><td>
<strong>
<a><xsl:attribute name="href">
<xsl:value-of select="v:email/@rdf:resource"/>
</xsl:attribute>
<xsl:value-of select="v:x-phonetic-first-name"/>
</a>
</strong><br/>(<em><xsl:value-of select="v:x-phonetic-last-name"/></em>)</td>
<td>
<xsl:value-of select="v:adr/rdf:Description/v:country-name"/>
<xsl:choose>
<xsl:when test="v:adr/rdf:Description/rdf:type[@rdf:resource='http://www.w3.org/2006/vcard/ns#Home']"> [Home]</xsl:when>
<xsl:when test="v:adr/rdf:Description/rdf:type[@rdf:resource='http://www.w3.org/2006/vcard/ns#Work']"> [Work]</xsl:when>
<xsl:otherwise> [Unknown]</xsl:otherwise>
</xsl:choose>
</td>
<td>
<xsl:value-of select="v:tel/rdf:Description/rdf:value"/>
<xsl:apply-templates select="v:tel/rdf:Description/rdf:type[@rdf:resource='http://www.w3.org/2006/vcard/ns#Home']"/>
</td>
</tr>
</xsl:for-each>

</table>
</body></html>
</xsl:template>

<xsl:template match="v:tel/rdf:Description/rdf:type[@rdf:resource='http://www.w3.org/2006/vcard/ns#Home']">
[Home]
</xsl:template>

</xsl:stylesheet>


$ java -cp ~/Dropbox/java/lib/saxon9he.jar net.sf.saxon.Transform -t -s:vcard-rdf-sample.xml -xsl:xslt-sample.xsl
Saxon-HE 9.3.0.4J from Saxonica
Java version 1.6.0_24
Warning: at xsl:stylesheet on line 5 column 17 of xslt-sample.xsl:
Running an XSLT 1 stylesheet with an XSLT 2 processor
Stylesheet compilation time: 392 milliseconds
Processing file:/Volumes/Macintosh%20HD2/Dropbox/xml/vcard-rdf-sample.xml
Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
Building tree for file:/Volumes/Macintosh%20HD2/Dropbox/xml/vcard-rdf-sample.xml using class net.sf.saxon.tree.tiny.TinyBuilder
Tree built in 5 milliseconds
Tree size: 273 nodes, 421 characters, 23 attributes
<html xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:v="http://www.w3.org/2006/vcard/ns#">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Addresses of VIP</title>
</head>
<body>
<h1>Addresses of Five VIPs</h1>
<table border="1">
<tr>
<th>Name</th>
<th>Country</th>
<th>Tel</th>
</tr>
<tr>
<td><strong><a href="mailto:ethan@example.com">Ethan</a></strong><br>(<em>Hawke</em>)
</td>
<td>USA [Unknown]</td>
<td>+61 7 7777 7777
[Home]

</td>
</tr>
<tr>
<td><strong><a href="mailto:corky@example.com">Corky</a></strong><br>(<em>Crystal</em>)
</td>
<td>Australia [Home]</td>
<td>+61 7 5555 5555
[Home]

</td>
</tr>
<tr>
<td><strong><a href="mailto:brad@example.com">Brad</a></strong><br>(<em>Pitt</em>)
</td>
<td>USA [Work]</td>
<td>+61 7 8888 8888</td>
</tr>
<tr>
<td><strong><a href="mailto:al@example.com">Al</a></strong><br>(<em>Pacino</em>)
</td>
<td>USA [Home]</td>
<td>+61 7 6666 6666</td>
</tr>
</table>
</body>
</html>Execution time: 83ms
Memory used: 4788984
NamePool contents: 49 entries in 47 chains. 8 prefixes, 8 URIs
$

2011年5月2日月曜日

[XML VQG] 2. XSLT (9)

Fourth example introduces xsl:if.


$ cat vcard-rdf-sample.xml
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:v="http://www.w3.org/2006/vcard/ns#">

<v:VCard rdf:about = "http://example.com/me/corky" >
<v:n>Corky Crystal</v:n>
<v:fn>Corky Crystal</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Corky</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Corky</v:sort-string>
<v:x-phonetic-first-name>Corky</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Crystal</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 5555 5555</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:corky@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>111 Lake Drive</v:street-address>
<v:locality>WonderCity</v:locality>
<v:postal-code>5555</v:postal-code>
<v:country-name>Australia</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
<v:VCard rdf:about = "http://example.com/me/al" >
<v:n>Al Pacino</v:n>
<v:fn>Al Pacino</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Al</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Al</v:sort-string>
<v:x-phonetic-first-name>Al</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Pacino</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 6666 6666</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Work"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:al@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>301 West 57th Street, 16C</v:street-address>
<v:locality>New York</v:locality>
<v:region>New York</v:region>
<v:postal-code>10017</v:postal-code>
<v:country-name>USA</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
<v:VCard rdf:about = "http://example.com/me/ethan" >
<v:n>Ethan Hawke</v:n>
<v:fn>Ethan Hawke</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Ethan</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Al</v:sort-string>
<v:x-phonetic-first-name>Ethan</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Hawke</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 7777 7777</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:ethan@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>c/o 1775 Broadway 701</v:street-address>
<v:locality>New York</v:locality>
<v:region>New York</v:region>
<v:postal-code>10019</v:postal-code>
<v:country-name>USA</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
<v:VCard rdf:about = "http://example.com/me/brad" >
<v:n>Brad Pitt</v:n>
<v:fn>Brad Pitt</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Brad</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Al</v:sort-string>
<v:x-phonetic-first-name>Brad</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Pitt</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 8888 8888</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Work"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:brad@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>9150 Wilshire Boulevard Suite 350</v:street-address>
<v:locality>Beverly Hills</v:locality>
<v:region>California</v:region>
<v:postal-code>90212</v:postal-code>
<v:country-name>USA</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Work"/>
</rdf:Description>
</v:adr>
</v:VCard>
</rdf:RDF>


$ cat 02-17.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:v="http://www.w3.org/2006/vcard/ns#"
version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html><head><title>Addresses of VIP</title></head>
<body>
<h1>Addresses of Five VIPs</h1>
<table border="1"><tr><th>Name</th><th>Country</th><th>Tel</th></tr>

<xsl:for-each select="rdf:RDF/v:VCard">
<tr><td><strong><xsl:value-of select="v:x-phonetic-first-name"/></strong><br/>(<em><xsl:value-of select="v:x-phonetic-last-name"/></em>)</td>
<td>
<xsl:value-of select="v:adr/rdf:Description/v:country-name"/>
<xsl:if test="v:adr/rdf:Description/rdf:type[@rdf:resource!='http://www.w3.org/2006/vcard/ns#Home']">
[Not home]
</xsl:if>
</td>
<td>
<xsl:value-of select="v:tel/rdf:Description/rdf:value"/>
<xsl:if test="v:tel/rdf:Description/rdf:type[@rdf:resource='http://www.w3.org/2006/vcard/ns#Home']">
[Home]
</xsl:if>
</td>
</tr>
</xsl:for-each>

</table>
</body></html>
</xsl:template>
</xsl:stylesheet>


$ java -cp ~/Dropbox/java/lib/saxon9he.jar net.sf.saxon.Transform -t -s:vcard-rdf-sample.xml -xsl:02-17.xsl
Saxon-HE 9.3.0.4J from Saxonica
Java version 1.6.0_24
Warning: at xsl:stylesheet on line 5 column 17 of 02-17.xsl:
Running an XSLT 1 stylesheet with an XSLT 2 processor
Stylesheet compilation time: 365 milliseconds
Processing file:/Volumes/Macintosh%20HD2/Dropbox/xml/vcard-rdf-sample.xml
Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
Building tree for file:/Volumes/Macintosh%20HD2/Dropbox/xml/vcard-rdf-sample.xml using class net.sf.saxon.tree.tiny.TinyBuilder
Tree built in 5 milliseconds
Tree size: 276 nodes, 416 characters, 24 attributes
<html xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:v="http://www.w3.org/2006/vcard/ns#">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Addresses of VIP</title>
</head>
<body>
<h1>Addresses of Five VIPs</h1>
<table border="1">
<tr>
<th>Name</th>
<th>Country</th>
<th>Tel</th>
</tr>
<tr>
<td><strong>Corky</strong><br>(<em>Crystal</em>)
</td>
<td>Australia</td>
<td>+61 7 5555 5555
[Home]

</td>
</tr>
<tr>
<td><strong>Al</strong><br>(<em>Pacino</em>)
</td>
<td>USA</td>
<td>+61 7 6666 6666</td>
</tr>
<tr>
<td><strong>Ethan</strong><br>(<em>Hawke</em>)
</td>
<td>USA</td>
<td>+61 7 7777 7777
[Home]

</td>
</tr>
<tr>
<td><strong>Brad</strong><br>(<em>Pitt</em>)
</td>
<td>USA
[Not home]

</td>
<td>+61 7 8888 8888</td>
</tr>
</table>
</body>
</html>Execution time: 99ms
Memory used: 4916080
NamePool contents: 44 entries in 42 chains. 8 prefixes, 8 URIs
$

[XML VQG] 2. XSLT (8)

Oops. 'vCard RDF' specification doesn't contain elements that have both a value and an attribute simultaneously. So I couldn't create an XSLT style sheet that uses attribute selection mechanism. Any way, here's third example.


$ cat vcard-rdf-sample.xml
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:v="http://www.w3.org/2006/vcard/ns#">

<v:VCard rdf:about = "http://example.com/me/corky" >
<v:n>Corky Crystal</v:n>
<v:fn>Corky Crystal</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Corky</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Corky</v:sort-string>
<v:x-phonetic-first-name>Corky</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Crystal</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 5555 5555</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:corky@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>111 Lake Drive</v:street-address>
<v:locality>WonderCity</v:locality>
<v:postal-code>5555</v:postal-code>
<v:country-name>Australia</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
<v:VCard rdf:about = "http://example.com/me/al" >
<v:n>Al Pacino</v:n>
<v:fn>Al Pacino</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Al</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Al</v:sort-string>
<v:x-phonetic-first-name>Al</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Pacino</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 6666 6666</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:al@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>301 West 57th Street, 16C</v:street-address>
<v:locality>New York</v:locality>
<v:region>New York</v:region>
<v:postal-code>10017</v:postal-code>
<v:country-name>USA</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
<v:VCard rdf:about = "http://example.com/me/ethan" >
<v:n>Ethan Hawke</v:n>
<v:fn>Ethan Hawke</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Ethan</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Al</v:sort-string>
<v:x-phonetic-first-name>Ethan</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Hawke</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 7777 7777</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:ethan@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>c/o 1775 Broadway 701</v:street-address>
<v:locality>New York</v:locality>
<v:region>New York</v:region>
<v:postal-code>10019</v:postal-code>
<v:country-name>USA</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
<v:VCard rdf:about = "http://example.com/me/brad" >
<v:n>Brad Pitt</v:n>
<v:fn>Brad Pitt</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Brad</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Al</v:sort-string>
<v:x-phonetic-first-name>Brad</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Pitt</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 8888 8888</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:brad@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>9150 Wilshire Boulevard Suite 350</v:street-address>
<v:locality>Beverly Hills</v:locality>
<v:region>California</v:region>
<v:postal-code>90212</v:postal-code>
<v:country-name>USA</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
</rdf:RDF>


$ cat 02-14.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:v="http://www.w3.org/2006/vcard/ns#"
version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html><head><title>Addresses of VIP</title></head>
<body>
<h1>Addresses of Five VIPs</h1>
<table border="1"><tr><th>Name</th><th>Country</th><th>Tel</th></tr>

<xsl:for-each select="rdf:RDF/v:VCard">
<tr><td><strong><xsl:value-of select="v:x-phonetic-first-name"/></strong><br/>(<em><xsl:value-of select="v:x-phonetic-last-name"/></em>)</td>
<td><xsl:value-of select="v:adr/rdf:Description/v:country-name"/></td>
<td><xsl:value-of select="v:tel/rdf:Description/rdf:value"/></td>
</tr>
</xsl:for-each>

</table>
</body></html>
</xsl:template>
</xsl:stylesheet>


$ java -cp ~/Dropbox/java/lib/saxon9he.jar net.sf.saxon.Transform -t -s:vcard-rdf-sample.xml -xsl:02-14.xsl
Saxon-HE 9.3.0.4J from Saxonica
Java version 1.6.0_24
Warning: at xsl:stylesheet on line 5 column 17 of 02-14.xsl:
Running an XSLT 1 stylesheet with an XSLT 2 processor
Stylesheet compilation time: 351 milliseconds
Processing file:/Volumes/Macintosh%20HD2/Dropbox/xml/vcard-rdf-sample.xml
Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
Building tree for file:/Volumes/Macintosh%20HD2/Dropbox/xml/vcard-rdf-sample.xml using class net.sf.saxon.tree.tiny.TinyBuilder
Tree built in 5 milliseconds
Tree size: 276 nodes, 416 characters, 24 attributes
<html xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:v="http://www.w3.org/2006/vcard/ns#">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Addresses of VIP</title>
</head>
<body>
<h1>Addresses of Five VIPs</h1>
<table border="1">
<tr>
<th>Name</th>
<th>Country</th>
<th>Tel</th>
</tr>
<tr>
<td><strong>Corky</strong><br>(<em>Crystal</em>)
</td>
<td>Australia</td>
<td>+61 7 5555 5555</td>
</tr>
<tr>
<td><strong>Al</strong><br>(<em>Pacino</em>)
</td>
<td>USA</td>
<td>+61 7 6666 6666</td>
</tr>
<tr>
<td><strong>Ethan</strong><br>(<em>Hawke</em>)
</td>
<td>USA</td>
<td>+61 7 7777 7777</td>
</tr>
<tr>
<td><strong>Brad</strong><br>(<em>Pitt</em>)
</td>
<td>USA</td>
<td>+61 7 8888 8888</td>
</tr>
</table>
</body>
</html>Execution time: 70ms
Memory used: 21770992
NamePool contents: 43 entries in 41 chains. 8 prefixes, 8 URIs
$

2011年5月1日日曜日

[XML VQG] 2. XSLT (7)

Second example.


$ cat 02-07.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html><head><title>Address list of VIPs</title></head>
<body>
<p align="center"><img src="corky.jpg" width="120" height="171"/></p>
<p>Blah, blah.
</p>
</body>
</html>

</xsl:template>
</xsl:stylesheet>


$ java -cp ~/Dropbox/java/lib/saxon9he.jar net.sf.saxon.Transform -t -s:02-01.xml -xsl:02-07.xsl
Saxon-HE 9.3.0.4J from Saxonica
Java version 1.6.0_24
Warning: at xsl:stylesheet on line 2 column 80 of 02-07.xsl:
Running an XSLT 1 stylesheet with an XSLT 2 processor
Stylesheet compilation time: 278 milliseconds
Processing file:/Volumes/Macintosh%20HD2/Dropbox/xml/02-01.xml
Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
Building tree for file:/Volumes/Macintosh%20HD2/Dropbox/xml/02-01.xml using class net.sf.saxon.tree.tiny.TinyBuilder
Tree built in 6 milliseconds
Tree size: 70 nodes, 100 characters, 6 attributes
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Address list of VIPs</title>
</head>
<body>
<p align="center"><img src="corky.jpg" width="120" height="171"></p>
<p>Blah, blah.

</p>
</body>
</html>Execution time: 42ms
Memory used: 14636736
NamePool contents: 39 entries in 38 chains. 8 prefixes, 8 URIs


$

2011年4月30日土曜日

[XML VQG] 2. XSLT (6)

First example.


$ cat 02-01.xml
<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="02-03.xsl"?>

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:v="http://www.w3.org/2006/vcard/ns#">

<v:VCard rdf:about = "http://example.com/me/corky" >
<v:n>Corky Crystal</v:n>
<v:fn>Corky Crystal</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Corky</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Corky</v:sort-string>
<v:x-phonetic-first-name>Corky</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Crystal</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 5555 5555</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:corky@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>111 Lake Drive</v:street-address>
<v:locality>WonderCity</v:locality>
<v:postal-code>5555</v:postal-code>
<v:country-name>Australia</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
</rdf:RDF>


$ cat 02-03.xsl
<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:v="http://www.w3.org/2006/vcard/ns#">

<xsl:template match="/">
<html><head><title>Addresses of World VIPs</title></head>
<body>
<h1>Addresses of World VIPs</h1>
<xsl:value-of select="rdf:RDF/v:VCard/v:n"/>
lives in
<xsl:value-of select="rdf:RDF/v:VCard/v:adr/rdf:Description/v:street-address"/>,<br/>
<xsl:value-of select="rdf:RDF/v:VCard/v:adr/rdf:Description/v:locality"/>,<br/>
<xsl:value-of select="rdf:RDF/v:VCard/v:adr/rdf:Description/v:postal-code"/>,<br/>
<xsl:value-of select="rdf:RDF/v:VCard/v:adr/rdf:Description/v:country-name"/>.
</body>
</html>
</xsl:template>
</xsl:stylesheet>


$ java -cp ~/Dropbox/java/lib/saxon9he.jar net.sf.saxon.Transform -t -s:02-01.xml -xsl:02-03.xsl
Saxon-HE 9.3.0.4J from Saxonica
Java version 1.6.0_24
Warning: at xsl:stylesheet on line 5 column 46 of 02-03.xsl:
Running an XSLT 1 stylesheet with an XSLT 2 processor
Stylesheet compilation time: 387 milliseconds
Processing file:/Volumes/Macintosh%20HD2/Dropbox/xml/02-01.xml
Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
Building tree for file:/Volumes/Macintosh%20HD2/Dropbox/xml/02-01.xml using class net.sf.saxon.tree.tiny.TinyBuilder
Tree built in 2 milliseconds
Tree size: 70 nodes, 100 characters, 6 attributes
<html xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:v="http://www.w3.org/2006/vcard/ns#">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Addresses of World VIPs</title>
</head>
<body>
<h1>Addresses of World VIPs</h1>Corky Crystal
lives in
111 Lake Drive,<br>WonderCity,<br>5555,<br>Australia.

</body>
</html>Execution time: 52ms
Memory used: 21394744
NamePool contents: 35 entries in 34 chains. 8 prefixes, 8 URIs
$

[XML VQG] 2. XSLT (5)

Let's resume learning XSLT. I should start from clarify the basic terminology of XSLT.


  • XSL: eXtensible Stylesheet Language

    XSL is a specification that provides several methods to format XML documents.
    W3C divided XSL into two parts:

    • XSLT: XSL Transformations

      Typically used when transforming XML documents into another XML documents or HTML documents. Some web browsers are capable of formatting XML files with XSLT.

      An XSLT processor transforms an XML document with an XSLT style sheet document.

      The XSLT style sheet contains templates that define instructions on how to transform nodes in the XML document.

    • XSL-FO: XSL Formatting Objects

      Typically used when transforming XML files into PDF files directly. No browser can deal with XSL-FO, so it needs dedicated application.

2011年4月24日日曜日

[XML VQG] 2. XSLT (4)

Most important thing is always data.

I consuleted VIP ADDRESS to create following RDF vCard example.


<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:v="http://www.w3.org/2006/vcard/ns#">

<v:VCard rdf:about = "http://example.com/me/corky" >
<v:n>Corky Crystal</v:n>
<v:fn>Corky Crystal</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Corky</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Corky</v:sort-string>
<v:x-phonetic-first-name>Corky</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Crystal</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 5555 5555</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:corky@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>111 Lake Drive</v:street-address>
<v:locality>WonderCity</v:locality>
<v:postal-code>5555</v:postal-code>
<v:country-name>Australia</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
<v:VCard rdf:about = "http://example.com/me/al" >
<v:n>Al Pacino</v:n>
<v:fn>Al Pacino</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Al</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Al</v:sort-string>
<v:x-phonetic-first-name>Al</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Pacino</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 6666 6666</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:al@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>301 West 57th Street, 16C</v:street-address>
<v:locality>New York</v:locality>
<v:region>New York</v:region>
<v:postal-code>10017</v:postal-code>
<v:country-name>USA</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
<v:VCard rdf:about = "http://example.com/me/ethan" >
<v:n>Ethan Hawke</v:n>
<v:fn>Ethan Hawke</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Ethan</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Al</v:sort-string>
<v:x-phonetic-first-name>Ethan</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Hawke</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 7777 7777</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:ethan@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>c/o 1775 Broadway 701</v:street-address>
<v:locality>New York</v:locality>
<v:region>New York</v:region>
<v:postal-code>10019</v:postal-code>
<v:country-name>USA</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
<v:VCard rdf:about = "http://example.com/me/brad" >
<v:n>Brad Pitt</v:n>
<v:fn>Brad Pitt</v:fn>
<v:sound>
<rdf:Description>
<rdf:value>Brad</rdf:value>
<rdf:type rdf:resource="@@@X-irmc-n@@@"/>
</rdf:Description>
</v:sound>
<v:sort-string>Al</v:sort-string>
<v:x-phonetic-first-name>Brad</v:x-phonetic-first-name>
<v:x-phonetic-last-name>Pitt</v:x-phonetic-last-name>
<v:tel>
<rdf:Description>
<rdf:value>+61 7 8888 8888</rdf:value>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
</rdf:Description>
</v:tel>
<v:email rdf:resource="mailto:brad@example.com"/>
<v:adr>
<rdf:Description>
<v:street-address>9150 Wilshire Boulevard Suite 350</v:street-address>
<v:locality>Beverly Hills</v:locality>
<v:region>California</v:region>
<v:postal-code>90212</v:postal-code>
<v:country-name>USA</v:country-name>
<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
</rdf:Description>
</v:adr>
</v:VCard>
</rdf:RDF>

2011年4月23日土曜日

[XML VQG] 2. XSLT (3)

I've finished creating my example related to vCard and RDF.


  • Original vCard

    BEGIN:VCARD
    VERSION:3.0
    N:Corky Crystal
    FN:Corky Crystal
    SOUND;X-IRMC-N:Corky;
    SORT-STRING:Corky
    X-PHONETIC-FIRST-NAME:Corky
    X-PHONETIC-LAST-NAME:Crystal
    TEL;HOME;VOIDE:+61 7 5555 5555
    EMAIL:corky@example.com
    ADR;HOME:;;111 Lake Drive;WonderCity;;5555;Australia
    END:VCARD


  • RDF vCard

    <?xml version="1.0"?>
    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:v="http://www.w3.org/2006/vcard/ns#">

    <v:VCard rdf:about = "http://example.com/me/corky" >
    <v:n>Corky Crystal</v:n>
    <v:fn>Corky Crystal</v:fn>
    <v:sound>
    <rdf:Description>
    <rdf:value>Corky</rdf:value>
    <rdf:type rdf:resource="@@@X-irmc-n@@@"/>
    </rdf:Description>
    </v:sound>
    <v:sort-string>Corky</v:sort-string>
    <v:x-phonetic-first-name>Corky</v:x-phonetic-first-name>
    <v:x-phonetic-last-name>Crystal</v:x-phonetic-last-name>
    <v:tel>
    <rdf:Description>
    <rdf:value>+61 7 5555 5555</rdf:value>
    <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
    <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Voice"/>
    </rdf:Description>
    </v:tel>
    <v:email rdf:resource="mailto:corky@example.com"/>
    <v:adr>
    <rdf:Description>
    <v:street-address>111 Lake Drive</v:street-address>
    <v:locality>WonderCity</v:locality>
    <v:postal-code>5555</v:postal-code>
    <v:country-name>Australia</v:country-name>
    <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home"/>
    </rdf:Description>
    </v:adr>
    </v:VCard>
    </rdf:RDF>


2011年4月12日火曜日

[XML VQG] 2. XSLT (2)

I was a bit disappointed at realizing that Google Chrome can't handle xml files with xsl. Safari can handle them.
And emacs seems to lack XML related tools, because there are no good elisps to deal with even XSLT.


  • Here, how to use Saxon on cui to run the examples in the book.


    bash-3.2$ java -cp ~/Dropbox/java/lib/saxon9he.jar net.sf.saxon.Transform -t -s:02-01.xml -xsl:02-03.xsl
    Saxon-HE 9.3.0.4J from Saxonica
    Java version 1.6.0_24
    Warning: at xsl:stylesheet on line 2 column 80 of 02-03.xsl:
    Running an XSLT 1 stylesheet with an XSLT 2 processor
    Stylesheet compilation time: 3222 milliseconds
    Processing file:/Volumes/Macintosh%20HD2/Dropbox/programming/xml-visual-quickstart-guide/Chapter_02_examples/02-01.xml
    Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
    Building tree for file:/Volumes/Macintosh%20HD2/Dropbox/programming/xml-visual-quickstart-guide/Chapter_02_examples/02-01.xml using class net.sf.saxon.tree.tiny.TinyBuilder
    Tree built in 1 milliseconds
    Tree size: 16 nodes, 32 characters, 1 attributes
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Wonders of the World</title>
    </head>
    <body>
    <h1>Wonders of the World</h1>



    The Colossus of Rhodes
    is located in Rhodes, Greece.


    </body>
    </html>Execution time: 320ms
    Memory used: 21579320
    NamePool contents: 19 entries in 19 chains. 6 prefixes, 6 URIs
    bash-3.2$


  • Hum, XSLT files are in the end XML files, and it must be well-formed. That kind of restriction must be not adequate as a template language.

  • As the content of sample xml files, ancient wonders are boring. So I'd better create my examples.

  • I've thought about which kind of data I should deal with as my own examples, and I realized that the address data would be fine with me. I'll adopt vCard objects in RDF as the xml vocabulary. [Representing vCard Objects in RDF]
    And you can also check what the vCard data in the wild are in my wiki entry. [aka:アドレス帳]

2011年4月9日土曜日

[XML VQG] 2. XSLT (1)

In this chapter, I should build xslt processing environment on my computer. I always prefer emacs as my kitchen sink, and found an minor-mode that interfaces with java xslt processors. [XSLT-process]

XSLT-process seems a frontend and it needs at least an xslt processor as its backend. I chose saxon as my xslt processor. [installation note]

2011年4月6日水曜日

[XML VQG] 1. Writing XML

On writing previous entry, I felt that taking-a-note style was not appropriate for this tiny but well-written book. Because my entry looks containing too much original content and I can't help feeling sorry to the authors... Well, I'd like to change the style of writing, so that my entries contain only what I myself felt or thought about the topics that comes from the book.

BTW, Part 1 'XML' contains only one chapter 'Writing XML', and it's well written for real beginners. Expressions, explanations and orders of material seems well considered. But I've got no new knowledge from this part.

2011年4月5日火曜日

[XML VQG] (Introductory sections)


  • Introduction

    • HTML is the first language of the web, and XML is the second language.
    • "HTML was designed to display information, XML was designed to manage it."

  • What is XML?

    • XML is a specification for;

      • storing information,
      • describing the structure of the information.

    • Here, the author try to explain these two points with a tiny example of XML documents. I felt something not so comfortable with the author's attitude, i.e. the author didn't mention explicitly the fact that the meaning of the tag or the information completely depends on the vocabulary of English (as a natural language).
    • In the end, XML is a set of rules for defining new markup languages whatever you like. This reminds me of FOL.

  • The Power of XML

    • XML suits for storing and carrying information, more that HTML do.
    • XML is easily extended and adapted, as compared with HTML.
    • XML document is simply a text file.
    • XML is open standard.

  • Extending XML

    • XML tags have no inherent formatting.
    • We have to define how to display it using other facility like XML (eXtensible Stylesheet Language).
    • XSL is composed of three parts;

      • XSLT
      • XPath
      • XSL-FO

    • There are also several ways to define the structures of XML document. DTD, XML Schema language and so on. We can use XML Namespace to extend XML Schema.

  • XML in Practice

    • RSS and Ajax are the good examples on how to use XML in practice.

  • About This Book

    • A Guided Tour
    • XML2e Companion Web Site (http://www.kehogo.com/xml2e)
    • From 2001 to 2008

  • What This Book is Not

    • This book is not exhaustive but introductory.



Oops. Learning something related to programming made me happy.

[XML VQG] Learning again?

I've been quite busy to learn English and doing many activities in international businesses.
In the mean time, I've always felt that I'd like to learn programming at the same time, but I couldn't.

Now I want to try again to learn it.

I selected XML as the subject for this trial. I'm still not sure I could continue to learn something regarding programming in my current situation, because my skill of English is not yet sufficient and needs a lot of time to improve it.

Any way, I'll try.

This time, my text book is "XML VISUAL QUICKSTART GUIDE". XML is a good old friend to me. I already know much about it. But I thought clarifying its basic notions would help me a lot at this timing.

That's all for prologue. Let's get started.