The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

Skip to content
Snippets Groups Projects
Commit 41848cea authored by Demian Katz's avatar Demian Katz
Browse files

Got XSLT working.

parent 3d16223d
No related merge requests found
......@@ -26,6 +26,7 @@
* @link http://vufind.org/wiki/ Wiki
*/
namespace VuFind\XSLT;
use DOMDocument, XSLTProcessor;
/**
* VuFind XSLT wrapper
......@@ -50,7 +51,7 @@ class Processor
{
$style = new DOMDocument();
// TODO: support local overrides
$style->load(APPLICATION_PATH . '/xsl/' . $xslt);
$style->load(APPLICATION_PATH . '/module/VuFind/xsl/' . $xslt);
$xsl = new XSLTProcessor();
$xsl->importStyleSheet($style);
$doc = new DOMDocument();
......
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- 8/19/04: ntra added "marc:" prefix to datafield element -->
<xsl:template name="datafield">
<xsl:param name="tag"/>
<xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
<xsl:param name="ind2"><xsl:text> </xsl:text></xsl:param>
<xsl:param name="subfields"/>
<xsl:element name="marc:datafield">
<xsl:attribute name="tag">
<xsl:value-of select="$tag"/>
</xsl:attribute>
<xsl:attribute name="ind1">
<xsl:value-of select="$ind1"/>
</xsl:attribute>
<xsl:attribute name="ind2">
<xsl:value-of select="$ind2"/>
</xsl:attribute>
<xsl:copy-of select="$subfields"/>
</xsl:element>
</xsl:template>
<xsl:template name="subfieldSelect">
<xsl:param name="codes">abcdefghijklmnopqrstuvwxyz</xsl:param>
<xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
<xsl:variable name="str">
<xsl:for-each select="marc:subfield">
<xsl:if test="contains($codes, @code)">
<xsl:value-of select="text()"/><xsl:value-of select="$delimeter"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
</xsl:template>
<xsl:template name="buildSpaces">
<xsl:param name="spaces"/>
<xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
<xsl:if test="$spaces>0">
<xsl:value-of select="$char"/>
<xsl:call-template name="buildSpaces">
<xsl:with-param name="spaces" select="$spaces - 1"/>
<xsl:with-param name="char" select="$char"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="chopPunctuation">
<xsl:param name="chopString"/>
<xsl:param name="punctuation"><xsl:text>.:,;/ </xsl:text></xsl:param>
<xsl:variable name="length" select="string-length($chopString)"/>
<xsl:choose>
<xsl:when test="$length=0"/>
<xsl:when test="contains($punctuation, substring($chopString,$length,1))">
<xsl:call-template name="chopPunctuation">
<xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
<xsl:with-param name="punctuation" select="$punctuation"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="not($chopString)"/>
<xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="chopPunctuationFront">
<xsl:param name="chopString"/>
<xsl:variable name="length" select="string-length($chopString)"/>
<xsl:choose>
<xsl:when test="$length=0"/>
<xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
<xsl:call-template name="chopPunctuationFront">
<xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="not($chopString)"/>
<xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:marc="http://www.loc.gov/MARC21/slim"
exclude-result-prefixes="marc">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="marc:record">
<table style="border: 0px;" class="citation">
<tr>
<th>LEADER</th>
<td colspan="3"><xsl:value-of select="//marc:leader"/></td>
</tr>
<xsl:apply-templates select="marc:datafield|marc:controlfield"/>
</table>
</xsl:template>
<xsl:template match="//marc:controlfield">
<tr>
<th style="text-align: right; vertical-align: top;">
<xsl:value-of select="@tag"/>
</th>
<td colspan="3"><xsl:value-of select="."/></td>
</tr>
</xsl:template>
<xsl:template match="//marc:datafield">
<tr>
<th style="text-align: right; vertical-align: top;">
<xsl:value-of select="@tag"/>
</th>
<td><xsl:value-of select="@ind1"/></td>
<td><xsl:value-of select="@ind2"/></td>
<td>
<xsl:apply-templates select="marc:subfield"/>
</td>
</tr>
</xsl:template>
<xsl:template match="marc:subfield">
<strong>|<xsl:value-of select="@code"/></strong>&#160;<xsl:value-of select="."/>&#160;
</xsl:template>
</xsl:stylesheet>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:zs="http://www.loc.gov/zing/srw/"
xmlns:marc="http://www.loc.gov/MARC21/slim">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<ResultSet>
<RecordCount><xsl:value-of select="//zs:numberOfRecords"/></RecordCount>
<xsl:call-template name="facet"/>
<xsl:call-template name="doc"/>
</ResultSet>
</xsl:template>
<xsl:template name="doc">
<xsl:for-each select="//zs:records/zs:record">
<record>
<id><xsl:value-of select=".//marc:controlfield[@tag=001]"/></id>
<xsl:if test=".//marc:datafield[@tag='245']/marc:subfield[@code='h']">
<format><xsl:value-of select=".//marc:datafield[@tag='245']/marc:subfield[@code='h']"/></format>
</xsl:if>
<language>
<xsl:value-of select="substring(.//marc:controlfield[@tag=008], 36, 3)"/>
</language>
<isbn>
<xsl:value-of select=".//marc:datafield[@tag='020']/marc:subfield[@code='a']"/>
</isbn>
<issn>
<xsl:value-of select=".//marc:datafield[@tag='022']/marc:subfield[@code='a']"/>
</issn>
<xsl:choose>
<xsl:when test=".//marc:datafield[@tag='090']">
<callnumber>
<xsl:value-of select=".//marc:datafield[@tag='090']/marc:subfield[@code='a']"/>
<xsl:value-of select=".//marc:datafield[@tag='090']/marc:subfield[@code='b']"/>
</callnumber>
</xsl:when>
<xsl:otherwise>
<xsl:if test=".//marc:datafield[@tag='050']">
<callnumber>
<xsl:value-of select=".//marc:datafield[@tag='050']/marc:subfield[@code='a']"/>
<xsl:value-of select=".//marc:datafield[@tag='050']/marc:subfield[@code='b']"/>
</callnumber>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:if test=".//marc:datafield[@tag='100']">
<author><xsl:value-of select=".//marc:datafield[@tag='100']/marc:subfield[@code='a']"/></author>
</xsl:if>
<title>
<xsl:value-of select=".//marc:datafield[@tag='245']/marc:subfield[@code='a']"/>
<xsl:if test=".//marc:datafield[@tag='245']/marc:subfield[@code='b']">
<xsl:text> </xsl:text>
<xsl:value-of select=".//marc:datafield[@tag='245']/marc:subfield[@code='b']"/>
</xsl:if>
</title>
<xsl:if test=".//datafield[@tag='260']">
<publisher><xsl:value-of select=".//datafield[@tag='260']/subfield[@code='b']"/></publisher>
<publishDate><xsl:value-of select=".//datafield[@tag='260']/subfield[@code='c']"/></publishDate>
</xsl:if>
<xsl:if test=".//datafield[@tag='440']">
<series><xsl:value-of select=".//marc:datafield[@tag='440']/marc:subfield[@code='a']"/></series>
</xsl:if>
<xsl:for-each select=".//marc:datafield[@tag='856']">
<url><xsl:value-of select="./marc:subfield[@code='u']"/></url>
</xsl:for-each>
<xsl:call-template name="holding"/>
</record>
</xsl:for-each>
</xsl:template>
<xsl:template name="facet">
<Facets>
<xsl:for-each select="//lst[@name='facet_fields']/lst">
<Cluster>
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
<xsl:for-each select="./int">
<xsl:variable name="elem" select="../@name"/>
<item>
<xsl:attribute name="count"><xsl:value-of select="."/></xsl:attribute>
<xsl:value-of select="@name"/>
</item>
</xsl:for-each>
</Cluster>
</xsl:for-each>
</Facets>
</xsl:template>
<xsl:template name="holding">
<xsl:for-each select=".//marc:datafield[@tag='952']">
<holdings>
<withdrawn><xsl:value-of select="./marc:subfield[@code='0']"/></withdrawn>
<itemlost><xsl:value-of select="./marc:subfield[@code='1']"/></itemlost>
<cn_source><xsl:value-of select="./marc:subfield[@code='2']"/></cn_source>
<materials><xsl:value-of select="./marc:subfield[@code='3']"/></materials>
<damaged><xsl:value-of select="./marc:subfield[@code='4']"/></damaged>
<restricted><xsl:value-of select="./marc:subfield[@code='5']"/></restricted>
<cn_sort><xsl:value-of select="./marc:subfield[@code='6']"/></cn_sort>
<notforloan><xsl:value-of select="./marc:subfield[@code='7']"/></notforloan>
<ccode><xsl:value-of select="./marc:subfield[@code='8']"/></ccode>
<itemnumber><xsl:value-of select="./marc:subfield[@code='9']"/></itemnumber>
<homebranch><xsl:value-of select="./marc:subfield[@code='a']"/></homebranch>
<holdingbranch><xsl:value-of select="./marc:subfield[@code='b']"/></holdingbranch>
<location><xsl:value-of select="./marc:subfield[@code='c']"/></location>
<dateaccessioned><xsl:value-of select="./marc:subfield[@code='d']"/></dateaccessioned>
<booksellerid><xsl:value-of select="./marc:subfield[@code='e']"/></booksellerid>
<coded_location_qualifier><xsl:value-of select="./marc:subfield[@code='f']"/></coded_location_qualifier>
<price><xsl:value-of select="./marc:subfield[@code='g']"/></price>
<renewals><xsl:value-of select="./marc:subfield[@code='j']"/></renewals>
<stack><xsl:value-of select="./marc:subfield[@code='j']"/></stack>
<issues><xsl:value-of select="./marc:subfield[@code='l']"/></issues>
<renewals><xsl:value-of select="./marc:subfield[@code='m']"/></renewals>
<reserves><xsl:value-of select="./marc:subfield[@code='n']"/></reserves>
<itemcallnumber><xsl:value-of select="./marc:subfield[@code='o']"/></itemcallnumber>
<barcode><xsl:value-of select="./marc:subfield[@code='p']"/></barcode>
<onloan><xsl:value-of select="./marc:subfield[@code='q']"/></onloan>
<datelastseen><xsl:value-of select="./marc:subfield[@code='r']"/></datelastseen>
<datelastborrowed><xsl:value-of select="./marc:subfield[@code='s']"/></datelastborrowed>
<copynumber><xsl:value-of select="./marc:subfield[@code='t']"/></copynumber>
<uri><xsl:value-of select="./marc:subfield[@code='u']"/></uri>
<replacementprice><xsl:value-of select="./marc:subfield[@code='v']"/></replacementprice>
<replacementpricedate><xsl:value-of select="./marc:subfield[@code='w']"/></replacementpricedate>
<paidfor><xsl:value-of select="./marc:subfield[@code='x']"/></paidfor>
<itype><xsl:value-of select="./marc:subfield[@code='y']"/></itype>
<itemnotes><xsl:value-of select="./marc:subfield[@code='z']"/></itemnotes>
</holdings>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
\ No newline at end of file
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<records>
<xsl:for-each select="//slim:record" xmlns:slim="http://www.loc.gov/MARC21/slim">
<xsl:element name="record">
<xsl:apply-templates/>
</xsl:element>
</xsl:for-each>
</records>
</xsl:template>
<!-- borrowed from http://wiki.tei-c.org/index.php/Remove-Namespaces.xsl: -->
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment