Skip to content

Instantly share code, notes, and snippets.

@ilantoren
Created September 10, 2015 14:08
Show Gist options
  • Save ilantoren/12b9309db17950bf9c97 to your computer and use it in GitHub Desktop.
Save ilantoren/12b9309db17950bf9c97 to your computer and use it in GitHub Desktop.
stylesheet experiment
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" encoding="UTF-8" />
<xsl:template match="/data">
<xsl:element name="html">
<head>
<title>OCLC matching to CARS files</title>
<style type="text/css">
table, td, tr, th {background:white; border:solid black 1pt;}
th { background:lightgrey }
.hit { font-weight:500; background-color:green}
.miss { background-color:red}
.close { background-color:FCC200}
</style>
</head>
<table>
<thead>
<tr>
<th>id</th>
<th>seq</th>
<th>score</th>
<th>year</th>
<th>source</th>
<th>title</th>
<th>author</th>
<th colspan="13">grade</th>
</tr>
</thead>
<xsl:for-each select="./perldata/hashref">
<!--xsl:if test="string-length(./item[@key = 'firstAuthor']) &gt; 0"-->
<xsl:apply-templates select="."/>
<!--/xsl:if-->
</xsl:for-each>
</table>
</xsl:element>
</xsl:template>
<xsl:template match="hashref">
<xsl:variable name="dsc">
<xsl:choose>
<xsl:when test= "number(item[@key='exactMatch']) eq 1"></xsl:when>
<xsl:when test="number(item[@key='yearmatch']) eq 0">.yr</xsl:when>
<xsl:when test="number(item[@key='exacttitle']) eq 1">.au</xsl:when>
<xsl:when test="number(item[@key='authormatch']) eq 1">.ti</xsl:when>
<xsl:otherwise>.ti.au</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<tr style="text-align:center">
<td rowspan="2">
<xsl:value-of select="item[@key='id']"/>
</td>
<td rowspan="2">
<xsl:value-of select="item[@key='seq']"/>
</td>
<td rowspan="2">
<xsl:choose>
<xsl:when test="item[@key='exactMatch'] = 1">
<xsl:attribute name="class">hit</xsl:attribute>
1
</xsl:when>
<xsl:when test="item[@key='closeMatch'] = 1">
<xsl:attribute name="class">close</xsl:attribute>
<xsl:value-of select="concat('1N', $dsc)"/>
</xsl:when>
<xsl:when test="not(item[@key='firstAuthor'])">
<xsl:attribute name="class">miss</xsl:attribute>
5
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="class">close</xsl:attribute>
<xsl:value-of select="concat('1N',$dsc)"/>
</xsl:otherwise>
</xsl:choose>
</td>
<td rowspan="2">
<xsl:if test="$dsc eq '.yr'">
<xsl:attribute name="style">background-color:yellow</xsl:attribute>
</xsl:if>
<xsl:element name="span">
<xsl:attribute name="title">
<xsl:value-of select="item[@key='year']"/>
</xsl:attribute>
<xsl:value-of select="item[@key='publicationyear']"/>
</xsl:element>
</td>
<td style="color:blue;font-weight:600">CARS</td>
<td style="text-align:left">
<xsl:if test="string-length(item[@key='title']) eq 0">
<xsl:attribute name="style">background-color:lightblue</xsl:attribute>
</xsl:if>
<xsl:value-of select="item[@key='sourcetitle']"/>
</td>
<td style="text-align:left">
<xsl:value-of select="item[@key='author']"/>
</td>
<xsl:apply-templates select="item[@key='exactMatch']" />
<xsl:apply-templates select="item[@key='closeMatch']" />
<xsl:apply-templates select=" item[@key='surnamematch'] "/>
<xsl:apply-templates select=" item[@key='authormatch'] "/>
<xsl:apply-templates select="item[@key='exacttitle']" />
<xsl:apply-templates select="item[@key='partialTitle']" />
<xsl:apply-templates select=" item[@key='yearmatch']" />
<xsl:apply-templates select=" item[@key='publishermatch']" />
<xsl:apply-templates select=" item[@key='titleleads'] " />
<xsl:apply-templates select=" item[@key='titletrails']" />
<xsl:apply-templates select=" item[@key='leadingtitle'] " />
<xsl:apply-templates select=" item[@key='trailingtitle'] " />
<xsl:apply-templates select=" item[@key='isbn'] " />
<xsl:apply-templates select=" item[@key='lcc']" />
</tr>
<tr>
<td style="color:green;font-weight:600">OCLC</td>
<xsl:element name="td">
<xsl:attribute name="style">
<xsl:choose>
<xsl:when test="$dsc eq '.ti' or $dsc eq '.ti.au'">text-align:left;background-color:yellow</xsl:when>
<xsl:otherwise>text-align:left</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="item[@key='title']"/>
</xsl:element>
<xsl:element name="td">
<xsl:attribute name="style">
<xsl:choose>
<xsl:when test="$dsc eq '.au' or $dsc eq '.ti.au'">text-align:left;background-color:yellow</xsl:when>
<xsl:otherwise>text-align:left</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="item[@key='firstAuthor']"/>
</xsl:element>
</tr>
<tr style="height:5px"/>
</xsl:template>
<xsl:template match="item">
<xsl:choose>
<xsl:when test=" number(.) &gt; number(0)">
<xsl:element name="td">
<xsl:attribute name="rowspan">2</xsl:attribute>
<xsl:attribute name="class">hit</xsl:attribute>
<xsl:element name="span">
<xsl:attribute name="title">
<xsl:value-of select="@key"/>
</xsl:attribute>
Y
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="td">
<xsl:attribute name="rowspan">2</xsl:attribute>
<xsl:attribute name="class">miss</xsl:attribute>
<xsl:element name="span">
<xsl:attribute name="title">
<xsl:value-of select="@key"/>
</xsl:attribute>
N
</xsl:element>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment