Commit a0e052df authored by Steinberg, Jan's avatar Steinberg, Jan

new test for giga import etc.

parent 102d7a69
......@@ -51,8 +51,9 @@ public class XmlXsltBundlesStreamSource implements BundlesStreamSource {
public Stream<Bundle> getBundlesStream() {
try {
TransformerFactory factory = TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl", TransformerFactoryImpl.class.getClassLoader() );
Templates xslTemplate = factory.newTemplates( new StreamSource( new StringReader(xslt) ) );
StringReader strReader = new StringReader(xslt);
StreamSource streamSource = new StreamSource( strReader );
Templates xslTemplate = factory.newTemplates( streamSource );
Source xmlInput = new StreamSource( new StringReader(xmlPayload) );
......
......@@ -276,6 +276,33 @@ public class XmlXsltBundlesStreamSourceTest {
assertEquals(1, metadata.stream().filter(m -> m.getKey().equals("dc.type.stock")).count() );
assertEquals("monograph", metadata.stream().filter(m -> m.getKey().equals("dc.type.stock")).findFirst().get().getValue() );
}
@Test
public void testGigaXml() throws IOException {
String gigaXmlString = IOUtils.toString(
getClass().
getClassLoader().
getResourceAsStream("xml/africa-spectrum/10.1177_186810261804700101.xml"), StandardCharsets.UTF_8);
LOG.info("gigaXmlString={}", gigaXmlString);
String xsltString = IOUtils.toString(
getClass().
getClassLoader().
getResourceAsStream("xslt/giga-2-xmlbundle.xslt"), StandardCharsets.UTF_8);
LOG.info("xsltString={}", xsltString);
XmlXsltBundlesStreamSource underTest = new XmlXsltBundlesStreamSource(gigaXmlString, xsltString, 6666);
Stream<Bundle> stream = underTest.getBundlesStream();
assertEquals(2, stream.count() );
assertEquals( "xmlxslt-bundlessource-6666", underTest.getReference() );
LOG.info("Under Test Ref: {}", underTest.getReference());
Bundle testBundle = underTest.getBundlesStream().filter(b -> b.getReference().equals("CCA@@10.1177_186810261804700101") ).findFirst().get();
assertEquals(1, testBundle.getMetadata().stream().filter(m -> m.getKey().equals("dc.title")).count() );
assertEquals("“Project Battle” or “Policy War”?: Protest, Advocacy, and the Outcomes of Environmental Contention in China", testBundle.getMetadata().stream().filter(m -> m.getKey().equals("dc.title")).findFirst().get().getValue() );
}
@Test
public void testTranscriptVerlagOnix() throws IOException {
......
This diff is collapsed.
This diff is collapsed.
......@@ -2,9 +2,10 @@
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:pica="info:srw/schema/5/picaXML-v1.0"
exclude-result-prefixes="pica"
>
<xsl:output indent="yes"/>
<xsl:output indent="yes" />
<xsl:strip-space elements="*"/>
<!-- <xsl:message terminate="no">here is the tree at the current node <xsl:copy-of select="."/> </xsl:message> -->
<!-- <xsl:message terminate="no">here is some message for stderr, e.g. <xsl:value-of select='text()' /> </xsl:message> -->
......@@ -46,8 +47,19 @@
<identifier>
<issn>0343-3668</issn>
</identifier>
<xsl:for-each select="record/datafield">
<xsl:if test="./tag = '31A'">
<source>
<volume>
<xsl:value-of select="./subfield/content"/>
</volume>
</source>
</xsl:if>
</xsl:for-each>
<xsl:apply-templates select="pica:record" />
</dc>
<xsl:apply-templates select="pica:record" />
</publication>
</xsl:template>
<xsl:template match="pica:record">
......@@ -58,7 +70,7 @@
<xsl:apply-templates select="pica:datafield[@tag='028C']"/>
<xsl:apply-templates select="pica:datafield[@tag='009P']"/>
</xsl:template>
<!--xsl:template match="pica:datafield[@tag='021A']">
<dc>
<title>
......@@ -66,85 +78,72 @@
</title>
</dc>
</xsl:template-->
<xsl:template match="pica:datafield[@tag='031A']">
<dc>
<source>
<xsl:if test="pica:subfield[@code='d']/text()">
<volume>
<xsl:value-of select="pica:subfield[@code='d']/text()"/>
</volume>
</xsl:if>
<xsl:if test="pica:subfield[@code='h']/text()">
<pageinfo>
<xsl:value-of select="pica:subfield[@code='h']/text()"/>
</pageinfo>
</xsl:if>
</source>
<xsl:if test="pica:subfield[@code='j']/text()">
<date>
<issued>
<xsl:value-of select="pica:subfield[@code='j']/text()"/>
</issued>
</date>
<source>
<xsl:if test="pica:subfield[@code='d']/text()">
<volume>
<xsl:value-of select="pica:subfield[@code='d']/text()"/>
</volume>
</xsl:if>
<xsl:if test="pica:subfield[@code='h']/text()">
<pageinfo>
<xsl:value-of select="pica:subfield[@code='h']/text()"/>
</pageinfo>
</xsl:if>
</source>
<xsl:if test="pica:subfield[@code='j']/text()">
<date>
<issued>
<xsl:value-of select="pica:subfield[@code='j']/text()"/>
</issued>
</date>
</xsl:if>
<xsl:choose>
<xsl:when test="string-length(/pica:record/pica:datafield[@tag='039I']/pica:subfield[@code='t']/text()) > 0">
<title>
<xsl:value-of select="/pica:record/pica:datafield[@tag='039I']/pica:subfield[@code='t']/text()"/>
</title>
</xsl:when>
<xsl:otherwise>
<title>
<xsl:value-of select="/pica:record/pica:datafield[@tag='021A']/pica:subfield[@code='a']/text()"/>
<xsl:if test="/pica:record/pica:datafield[@tag='021A']/pica:subfield[@code='d']">
<xsl:text>: </xsl:text>
<xsl:value-of select="/pica:record/pica:datafield[@tag='021A']/pica:subfield[@code='d']/text()"/>
</xsl:if>
<xsl:choose>
<xsl:when test="string-length(/pica:record/pica:datafield[@tag='039I']/pica:subfield[@code='t']/text()) > 0">
<title>
<xsl:value-of select="/pica:record/pica:datafield[@tag='039I']/pica:subfield[@code='t']/text()"/>
</title>
</xsl:when>
<xsl:otherwise>
<title>
<xsl:value-of select="/pica:record/pica:datafield[@tag='021A']/pica:subfield[@code='a']/text()"/>
<xsl:if test="/pica:record/pica:datafield[@tag='021A']/pica:subfield[@code='d']">
<xsl:text>: </xsl:text>
<xsl:value-of select="/pica:record/pica:datafield[@tag='021A']/pica:subfield[@code='d']/text()"/>
</xsl:if>
</title>
</xsl:otherwise>
</xsl:choose>
</dc>
</xsl:template>
</title>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="pica:datafield[@tag='028A']">
<dc>
<contributor>
<author>
<xsl:value-of select="pica:subfield[@code='a'][1]/text()"/>, <xsl:value-of select="pica:subfield[@code='d'][1]/text()"/>
</author>
</contributor>
</dc>
</xsl:template>
<contributor>
<author>
<xsl:value-of select="pica:subfield[@code='a'][1]/text()"/>, <xsl:value-of select="pica:subfield[@code='d'][1]/text()"/>
</author>
</contributor>
</xsl:template>
<xsl:template match="pica:datafield[@tag='027D']">
<dc>
<source>
<journal>
<xsl:value-of select="pica:subfield[@code='a']/text()"/>
</journal>
</source>
</dc>
<source>
<journal>
<xsl:value-of select="pica:subfield[@code='a']/text()"/>
</journal>
</source>
</xsl:template>
<xsl:template match="pica:datafield[@tag='028C']">
<dc>
<contributor>
<author>
<xsl:value-of select="pica:subfield[@code='a'][1]/text()"/>, <xsl:value-of select="pica:subfield[@code='d'][1]/text()"/>
</author>
</contributor>
</dc>
</xsl:template>
<contributor>
<author>
<xsl:value-of select="pica:subfield[@code='a'][1]/text()"/>, <xsl:value-of select="pica:subfield[@code='d'][1]/text()"/>
</author>
</contributor>
</xsl:template>
<xsl:template match="pica:datafield[@tag='009P']">
<dc>
<identifier>
<url>
<xsl:value-of select="pica:subfield[@code='a']/text()"/>
</url>
</identifier>
</dc>
<identifier>
<url>
<xsl:value-of select="pica:subfield[@code='a']/text()"/>
</url>
</identifier>
</xsl:template>
</xsl:stylesheet>
\ No newline at end of file
Markdown is supported
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