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
$

0 件のコメント: