Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## 0.7.0

- escape double quotes, LF and CR and backslash in literals as
required by the [N-Triples specs, sec. 2.3 RDF
Literals](https://www.w3.org/TR/n-triples/#sec-literals). Escaping
must already be done by the XTriples processor, i.e. in the XSLT
stylesheet. This fixes issue #6.
- reverts escaping done in 0.6.4 from the recipes

## 0.6.3

escape double quotes in extracted literals
Expand Down
6 changes: 3 additions & 3 deletions recipes/tei/crm-entities.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ target/bin/xslt.sh -xsl:xsl/extract-param-doc.xsl -s:recipes/tei/crm-entity-name
<condition>/$repeatIndex eq 1</condition>
<subject prefix="ent">/concat(local-name(.), '#', @xml:id)</subject>
<predicate prefix="crm">P48_has_preferred_identifier</predicate>
<object type="bnode">/concat('entityIdentifier_', local-name(.), '_', $resourceIndex, '_', $repeatIndex)=>replace('&quot;', '&amp;quot;')</object>
<object type="bnode">/concat('entityIdentifier_', local-name(.), '_', $resourceIndex, '_', $repeatIndex)</object>
</statement>

<!-- identifiers from all names -->
<statement repeat="{/count(*[self::tei:name or self::tei:persName or self::tei:placeName or self::tei:orgName or self::tei:eventName]) }">
<subject prefix="ent">/concat(local-name(.), '#', @xml:id)</subject>
<predicate prefix="crm">P1_is_identified_by</predicate>
<object type="bnode">/concat('entityIdentifier_', local-name(.), '_', $resourceIndex, '_', $repeatIndex)=>replace('&quot;', '&amp;quot;')</object>
<object type="bnode">/concat('entityIdentifier_', local-name(.), '_', $resourceIndex, '_', $repeatIndex)</object>
</statement>
<statement repeat="{/count(*[self::tei:name or self::tei:persName or self::tei:placeName or self::tei:orgName or self::tei:eventName]) }">
<subject type="bnode">/concat('entityIdentifier_', local-name(.), '_', $resourceIndex, '_', $repeatIndex)</subject>
Expand All @@ -80,7 +80,7 @@ target/bin/xslt.sh -xsl:xsl/extract-param-doc.xsl -s:recipes/tei/crm-entity-name
<subject type="bnode">/concat('entityIdentifier_', local-name(.), '_', $resourceIndex, '_', $repeatIndex)</subject>
<!-- sdh:P21 = sdh:P100_has_value see https://ontome.net/property/1843/namespace/3#identification -->
<predicate prefix="sdh">P21</predicate>
<object type="literal">/*[$repeatIndex]=>normalize-space()=>replace('&quot;', '&amp;quot;')</object>
<object type="literal">/*[$repeatIndex]=>normalize-space()</object>
</statement>
<statement repeat="{/count(*[self::tei:name or self::tei:persName or self::tei:placeName or self::tei:orgName or self::tei:eventName]) }">
<subject type="bnode">/concat('entityIdentifier_', local-name(.), '_', $resourceIndex, '_', $repeatIndex)</subject>
Expand Down
4 changes: 2 additions & 2 deletions recipes/tei/lincs-entities.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ target/bin/xslt.sh -xsl:xsl/extract-param-doc.xsl -s:recipes/tei/lincs-entities.
<statement>
<subject type="bnode">/concat('attributeAssignment', $resourceIndex)</subject>
<predicate prefix="crm">P3_has_note</predicate>
<object type="literal">/normalize-space(.)=>replace('&quot;', '&amp;quot;')</object>
<object type="literal">/normalize-space(.)</object>
</statement>
<statement>
<subject type="bnode">/concat('attributeAssignment', $resourceIndex)</subject>
Expand Down Expand Up @@ -223,7 +223,7 @@ target/bin/xslt.sh -xsl:xsl/extract-param-doc.xsl -s:recipes/tei/lincs-entities.
<statement>
<subject type="bnode">/concat('quote', $resourceIndex)</subject>
<predicate prefix="oa">exact</predicate>
<object type="literal">/normalize-space(.)=>replace('&quot;', '&amp;quot;')</object>
<object type="literal">/normalize-space(.)</object>
</statement>
<statement>
<condition>/exists(function-lookup(xs:QName('utils:prefix'), 1))</condition>
Expand Down
2 changes: 1 addition & 1 deletion recipes/tei/tei-entities.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ target/bin/xslt.sh -xsl:xsl/extract-param-doc.xsl -s:recipes/tei/crm-entity-name
<statement repeat="{/count(*[self::tei:desc or self::tei:note]) }">
<subject type="bnode">/concat('description_', local-name(.), '_', $resourceIndex, '_', $repeatIndex)</subject>
<predicate prefix="sdh">P21</predicate>
<object type="literal">/*[self::tei:desc or self::tei:note][$repeatIndex]=>normalize-space()=>replace('&quot;', '&amp;quot;')</object>
<object type="literal">/*[self::tei:desc or self::tei:note][$repeatIndex]=>normalize-space()</object>
</statement>
<statement repeat="{/count(*[self::tei:desc or self::tei:note]) }">
<subject type="bnode">/concat('description_', local-name(.), '_', $resourceIndex, '_', $repeatIndex)</subject>
Expand Down
24 changes: 24 additions & 0 deletions test/backslash.tei.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml"
schematypens="http://purl.oclc.org/dsdl/schematron"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title>\Title\</title>
</titleStmt>
<publicationStmt>
<p>Publication Information</p>
</publicationStmt>
<sourceDesc>
<p>Information about the source</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<p>Some text here.</p>
</body>
</text>
</TEI>
25 changes: 25 additions & 0 deletions test/cr-lf.tei.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml"
schematypens="http://purl.oclc.org/dsdl/schematron"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title xml:space="preserve">Title
with&#xd;&#xa;new lines</title>
</titleStmt>
<publicationStmt>
<p>Publication Information</p>
</publicationStmt>
<sourceDesc>
<p>Information about the source</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<p>Some text here.</p>
</body>
</text>
</TEI>
24 changes: 24 additions & 0 deletions test/quote.tei.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml"
schematypens="http://purl.oclc.org/dsdl/schematron"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title>"Title"</title>
</titleStmt>
<publicationStmt>
<p>Publication Information</p>
</publicationStmt>
<sourceDesc>
<p>Information about the source</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<p>Some text here.</p>
</body>
</text>
</TEI>
15 changes: 14 additions & 1 deletion xsl/xtriples.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,13 @@ This is only a module and should be imported by some calling stylesheet.
<xsl:when test="$part/@type eq 'literal' or $part/self::object[not(@type)]">
<xsl:value-of>
<xsl:text>"</xsl:text>
<xsl:value-of select="$x"/>
<!-- try to escape, however, some types cannot be escaped -->
<xsl:try>
<xsl:value-of select="$x => xtriples:escape-literal()"/>
<xsl:catch>
<xsl:value-of select="$x"/>
</xsl:catch>
</xsl:try>
<xsl:text>"</xsl:text>
<xsl:choose>
<!--
Expand Down Expand Up @@ -304,6 +310,13 @@ This is only a module and should be imported by some calling stylesheet.
</xsl:for-each>
</xsl:function>

<xsl:function name="xtriples:escape-literal" as="xs:string">
<xsl:param name="unescaped" as="xs:string"/>
<xsl:value-of
select="$unescaped => replace('\\', '\\\\') => replace('&#xa;', '\\n') => replace('&#xd;', '\\r') => replace('&quot;', '\\&quot;')"
/>
</xsl:function>

<xsl:function name="xtriples:serialize">
<xsl:param name="sentence-parts" as="item()*"/>
<xsl:for-each select="$sentence-parts">
Expand Down
30 changes: 30 additions & 0 deletions xsl/xtriples.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,34 @@
select="'&quot;Es ist alles eitel 2.0&quot;'"/>
</x:scenario>

<x:scenario label="double quotes in literals are escaped">
<x:call template="xtriples:extract">
<x:param name="config" href="../test/config-01.xml"/>
<x:param name="resource" href="../test/quote.tei.xml"/>
<x:param name="resource-index" select="1"/>
</x:call>
<x:expect label="quote escaped in literal" as="xs:string" test="$x:result[3]"
select="'&quot;\&quot;Title\&quot;&quot;'"/>
</x:scenario>

<x:scenario label="backslashed in literals are escaped">
<x:call template="xtriples:extract">
<x:param name="config" href="../test/config-01.xml"/>
<x:param name="resource" href="../test/backslash.tei.xml"/>
<x:param name="resource-index" select="1"/>
</x:call>
<x:expect label="backslash escaped in literal" as="xs:string" test="$x:result[3]"
select="'&quot;\\Title\\&quot;'"/>
</x:scenario>

<x:scenario label="CR and LF in literals are escaped">
<x:call template="xtriples:extract">
<x:param name="config" href="../test/config-01.xml"/>
<x:param name="resource" href="../test/cr-lf.tei.xml"/>
<x:param name="resource-index" select="1"/>
</x:call>
<x:expect label="CR and LF escaped in literal" as="xs:string" test="$x:result[3]"
select="'&quot;Title\nwith\r\nnew lines&quot;'"/>
</x:scenario>

</x:description>
Loading