1 | <!-- |
---|
2 | Produce a reference entry based on an Amazon ASIN (ISBN) entry. |
---|
3 | |
---|
4 | Copyright (c) 2006, Julian Reschke (julian.reschke@greenbytes.de) |
---|
5 | All rights reserved. |
---|
6 | |
---|
7 | Redistribution and use in source and binary forms, with or without |
---|
8 | modification, are permitted provided that the following conditions are met: |
---|
9 | |
---|
10 | * Redistributions of source code must retain the above copyright notice, |
---|
11 | this list of conditions and the following disclaimer. |
---|
12 | * Redistributions in binary form must reproduce the above copyright notice, |
---|
13 | this list of conditions and the following disclaimer in the documentation |
---|
14 | and/or other materials provided with the distribution. |
---|
15 | * Neither the name of Julian Reschke nor the names of its contributors |
---|
16 | may be used to endorse or promote products derived from this software |
---|
17 | without specific prior written permission. |
---|
18 | |
---|
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
29 | POSSIBILITY OF SUCH DAMAGE. |
---|
30 | --> |
---|
31 | |
---|
32 | <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
---|
33 | version="1.0" |
---|
34 | > |
---|
35 | |
---|
36 | <xsl:output indent="yes"/> |
---|
37 | |
---|
38 | <xsl:param name="asin" /> |
---|
39 | |
---|
40 | <xsl:template match="/"> |
---|
41 | <xsl:variable name="uri" select="concat('http://xml.amazon.com/onca/xml3?t=webservices-20&dev-t=foobar&AsinSearch=',$asin,'&type=heavy&f=xml')" /> |
---|
42 | <xsl:variable name="res" select="document($uri)" /> |
---|
43 | <references> |
---|
44 | <xsl:apply-templates select="$res/ProductInfo/Details" /> |
---|
45 | </references> |
---|
46 | </xsl:template> |
---|
47 | |
---|
48 | <xsl:template name="initials"> |
---|
49 | <xsl:param name="str"/> |
---|
50 | <xsl:choose> |
---|
51 | <xsl:when test="contains($str,' ')"> |
---|
52 | <xsl:call-template name="initials"> |
---|
53 | <xsl:with-param name="str"> |
---|
54 | <xsl:value-of select="substring-before($str,' ')"/> |
---|
55 | </xsl:with-param> |
---|
56 | </xsl:call-template> |
---|
57 | <xsl:call-template name="initials"> |
---|
58 | <xsl:with-param name="str"> |
---|
59 | <xsl:value-of select="substring-after($str,' ')"/> |
---|
60 | </xsl:with-param> |
---|
61 | </xsl:call-template> |
---|
62 | </xsl:when> |
---|
63 | <xsl:otherwise><xsl:value-of select="substring($str,1,1)"/>. </xsl:otherwise> |
---|
64 | </xsl:choose> |
---|
65 | </xsl:template> |
---|
66 | |
---|
67 | <xsl:template name="get-surname"> |
---|
68 | <xsl:param name="str"/> |
---|
69 | <xsl:choose> |
---|
70 | <xsl:when test="contains($str,' ')"> |
---|
71 | <xsl:call-template name="get-surname"> |
---|
72 | <xsl:with-param name="str" select="substring-after($str,' ')"/> |
---|
73 | </xsl:call-template> |
---|
74 | </xsl:when> |
---|
75 | <xsl:otherwise> |
---|
76 | <xsl:value-of select="$str"/> |
---|
77 | </xsl:otherwise> |
---|
78 | </xsl:choose> |
---|
79 | </xsl:template> |
---|
80 | |
---|
81 | <xsl:template match="Author"> |
---|
82 | <xsl:variable name="surname"> |
---|
83 | <xsl:call-template name="get-surname"> |
---|
84 | <xsl:with-param name="str" select="normalize-space(.)"/> |
---|
85 | </xsl:call-template> |
---|
86 | </xsl:variable> |
---|
87 | <xsl:variable name="givenname"> |
---|
88 | <xsl:value-of select="normalize-space(substring-before(.,$surname))"/> |
---|
89 | </xsl:variable> |
---|
90 | <author surname="{$surname}" fullname="{$givenname} {$surname}"> |
---|
91 | <xsl:attribute name="initials"> |
---|
92 | <xsl:call-template name="initials"> |
---|
93 | <xsl:with-param name="str" select="$givenname"/> |
---|
94 | </xsl:call-template> |
---|
95 | </xsl:attribute> |
---|
96 | <organization/> |
---|
97 | </author> |
---|
98 | </xsl:template> |
---|
99 | |
---|
100 | <xsl:template match="Details"> |
---|
101 | <reference target="urn:isbn:{Isbn}"> |
---|
102 | <front> |
---|
103 | <xsl:apply-templates select="ProductName"/> |
---|
104 | <xsl:apply-templates select="Authors/Author"/> |
---|
105 | <xsl:apply-templates select="ReleaseDate"/> |
---|
106 | </front> |
---|
107 | <xsl:apply-templates select="Manufacturer"/> |
---|
108 | </reference> |
---|
109 | </xsl:template> |
---|
110 | |
---|
111 | <xsl:template match="ReleaseDate"> |
---|
112 | <xsl:variable name="part1" select="normalize-space(substring-before(.,','))" /> |
---|
113 | <xsl:variable name="part2" select="normalize-space(substring-after(.,','))" /> |
---|
114 | <date year="{$part2}"> |
---|
115 | <xsl:choose> |
---|
116 | <xsl:when test="contains($part1,' ')"> |
---|
117 | <xsl:attribute name="month"> |
---|
118 | <xsl:value-of select="substring-after($part1,' ')" /> |
---|
119 | </xsl:attribute> |
---|
120 | </xsl:when> |
---|
121 | <xsl:otherwise> |
---|
122 | <xsl:attribute name="month"> |
---|
123 | <xsl:value-of select="$part1" /> |
---|
124 | </xsl:attribute> |
---|
125 | </xsl:otherwise> |
---|
126 | </xsl:choose> |
---|
127 | </date> |
---|
128 | </xsl:template> |
---|
129 | |
---|
130 | <xsl:template match="ProductName"> |
---|
131 | <title><xsl:value-of select="."/></title> |
---|
132 | </xsl:template> |
---|
133 | |
---|
134 | <xsl:template match="Manufacturer"> |
---|
135 | <seriesInfo name="{.}" value="" /> |
---|
136 | </xsl:template> |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | </xsl:transform> |
---|