<?xml version="1.0" encoding="ISO-8859-1"?>
<BK xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xsl:version="2.0">
<!--Written by Emma Barnes, SnowAngels Publishing Services: a division of Snowbooks the book publishers.
7th January 2008
Version 1.0
Contact SnowAngels: emma@snowbooks.com     0044 207 837 6482   120 Pentonville Road, London N1 9JN
View videos and training advice at www.snowbooks.com/angels_IT.html-->

<!-- This XSL transforms an ONIX message into XML suitable for importing into Adobe InDesign CS3. For an InDesign template set up to use this XML, contact Emma Barnes, above -->

<!-- Start of a loop that looks at each book within the ONIX message-->
  <xsl:for-each select="ONIXMessage/Product">
<!-- Sorts the results of this XSL by BIC Category-->
  <xsl:sort select="BICMainSubject"/>
<!-- Starts to define the output XML -->
  	<Book>
<!-- Sets variables which will be used in the XSL to follow. These variables are set more for convenience than anything, so that the XSL doesn't get too complicated -->
  		<xsl:variable name="bk" select="Title/TitleText"/>
  		<xsl:variable name="xx" select="ProductFormDetail"/>
  		<xsl:variable name="dt" select="PublicationDate"/>
  		<xsl:variable name="isbn" select="ProductIdentifier[ProductIDType = '03']/IDValue"/>
  		<xsl:variable name="bic" select="BICMainSubject"/>
<!-- Sets a link to the product images. This path will have to be changed according to your internal filing system and image naming convention. Ours are all called thumb9781905005xxx.jpg, where the number is the ISBN of the title. -->
  		<image href="H:\Snowbooks infrastructure\IT\SNOWBOOKS.COM\thumb{$isbn}.jpg" />
<!-- Start of a loop to take the ugly BIC codes and turn them into something human-readable. If you publish booksin more categories than this, you should duplicate one of the lines and change the following details:
                                      <xsl:when test="$bic = '[put the bic code here, and delete the square brackets]'">[write the name of the category here, and delete the square brackets]</xsl:when> -->
  		<category>
                               <xsl:choose>
					<xsl:when test="$bic = 'FH'">Thriller</xsl:when>
					<xsl:when test="$bic = 'FF'">Crime</xsl:when>
					<xsl:when test="$bic = 'FA'">Fiction</xsl:when>
					<xsl:when test="$bic = 'FC'">Classics</xsl:when>
					<xsl:when test="$bic = 'FV'">Historical fiction</xsl:when>
					<xsl:when test="$bic = 'BM'">Memoir</xsl:when>
					<xsl:when test="$bic = 'FH'">Horror</xsl:when>
					<xsl:when test="$bic = 'FM'">Fantasy</xsl:when>
					<xsl:when test="$bic = 'DNF'">Literature</xsl:when>
					<xsl:otherwise>General non fiction</xsl:otherwise>
				</xsl:choose></category>
<!-- Selects the title-->
 		<title><xsl:value-of select="$bk"/></title>
<!-- Selects the author's name -->
  		<authorfirstname><xsl:value-of select="Contributor/NamesBeforeKey"/></authorfirstname>
  		<authorlastname><xsl:value-of select="Contributor/KeyNames"/></authorlastname>
<!-- Selects the blurb-->
		<description><xsl:value-of select="OtherText[TextTypeCode = '01']/Text"/></description>
<!-- Selects the pub date-->
                <year><xsl:value-of select="concat(substring($dt,7,2), '/',substring($dt,5,2), '/',substring($dt,1,4))"/></year>
<!-- Start of a loop that selects the format, in the same way that we rewrote the categories, above. Just like above, you can add additional 'when' statements.-->
		<format>
				<xsl:choose>
					<xsl:when test="$xx = 'B104'">A Format Paperback</xsl:when>
					<xsl:when test="$xx = 'B105'">B Format Paperback</xsl:when>
					<xsl:when test="$xx = 'B106'">Full Colour paperback</xsl:when>
					<xsl:otherwise>Hardback</xsl:otherwise>
				</xsl:choose></format>
<!-- Selects the ISBN. We could have used the isbn variable set above for this-->
                 <productid><xsl:value-of select="ProductIdentifier[ProductIDType = '03']/IDValue"/></productid>
<!-- Selects the price-->
                 <price><xsl:value-of select="SupplyDetail/Price/PriceAmount"/></price>
<!-- Marks the end of each book record in the output XML-->
	</Book>
<!-- The end of the loop which looks at each book in the ONIX record.-->
  </xsl:for-each>
<!-- Marks the end of the XML file-->
</BK>
