Skip to content

Commit

Permalink
Merge pull request #626 from openSUSE/jsonld-for-sbp-trd
Browse files Browse the repository at this point in the history
Fix some JSON-LD problems
  • Loading branch information
tomschr authored May 13, 2024
2 parents f4eb3c4 + 3703e63 commit 3699d03
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
6 changes: 5 additions & 1 deletion sbp/xhtml/chunk.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@

<xsl:param name="is.chunk" select="1"/>

</xsl:stylesheet>
<xsl:template match="/">
<xsl:apply-imports/>
<xsl:call-template name="handle-json-ld"/>
</xsl:template>
</xsl:stylesheet>
4 changes: 1 addition & 3 deletions sbp/xhtml/titlepage.templates.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@
</xsl:template>

<xsl:template match="d:info/d:abstract" mode="article.titlepage.recto.auto.mode">
<xsl:message>d:info/d:abstract</xsl:message>
<div class="abstract">
<xsl:apply-templates mode="article.titlepage.recto.auto.mode"/>
</div>
</xsl:template>
<xsl:template match="d:info/d:abstract/d:title" mode="article.titlepage.recto.auto.mode">
<xsl:message>d:info/d:abstract/d:title</xsl:message>
<div class="title">
<xsl:apply-templates/>
</div>
Expand Down Expand Up @@ -281,4 +279,4 @@
<xsl:apply-templates mode="article.titlepage.recto.auto.mode" select="d:info/d:copyright"/>
</xsl:template>

</xsl:stylesheet>
</xsl:stylesheet>
43 changes: 23 additions & 20 deletions suse2022-ns/xhtml/json-ld.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,15 @@
<xsl:variable name="lang">
<xsl:call-template name="l10n.language"/>
</xsl:variable>
<xsl:message>Going to write external JSON-LD structure to "<xsl:value-of

<!-- <xsl:message>Going to write external JSON-LD structure to "<xsl:value-of
select="$filename"/>" for <xsl:value-of select="local-name($node)"/>
Found <xsl:value-of select="count($stitchxml)"/> node(s) (=<xsl:value-of select="local-name($stitchxml)"/>).
<xsl:if test="$dcfilename">Found DC filename "<xsl:value-of select="$dcfilename"/>"</xsl:if>
json-ld-base.dir="<xsl:value-of select="$json-ld-base.dir"/>"
filename="<xsl:value-of select="$filename"/>"
</xsl:message>

-->
<!-- We take into account the language as well -->
<xsl:call-template name="write.chunk">
<xsl:with-param name="filename" select="concat($json-ld-base.dir, $lang, '-', $filename)"/>
Expand Down Expand Up @@ -467,7 +467,7 @@
<xsl:template name="generate-json-ld">
<xsl:param name="node" select="."/>
<xsl:if test="$generate.json-ld != 0">
<xsl:message>INFO: Going to generate JSON-LD... ("<xsl:value-of select="$stitchfile"/>") for context element <xsl:value-of select="local-name($node)"/></xsl:message>
<xsl:message>INFO: Going to generate JSON-LD... (stitchfile="<xsl:value-of select="$stitchfile"/>") for context element <xsl:value-of select="local-name($node)"/></xsl:message>
<script type="application/ld+json">
<xsl:call-template name="generate-json-content">
<xsl:with-param name="node" select="$node"/>
Expand Down Expand Up @@ -713,24 +713,15 @@
<xsl:param name="node" select="."/>
<xsl:variable name="candidate-modified">
<xsl:choose>
<xsl:when test="$node/d:info/d:revhistory/d:revision[1]/d:date">
<xsl:value-of select="normalize-space(string($node/d:info/d:revhistory/d:revision[1]/d:date))"/>
</xsl:when>
<xsl:when test="$node/ancestor-or-self::*/d:info/d:revhistory/d:revision[1]/d:date">
<xsl:value-of select="normalize-space(string($node/ancestor-or-self::*/d:info/d:revhistory/d:revision[1]/d:date))"/>
<xsl:value-of select="normalize-space(($node/ancestor-or-self::*/d:info/d:revhistory/d:revision[1]/d:date)[last()])"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="candidate-published">
<xsl:choose>
<xsl:when test="$node/d:info/d:revhistory/d:revision[last()]/d:date">
<xsl:value-of select="normalize-space(string($node/d:info/d:revhistory/d:revision[last()]/d:date))"/>
</xsl:when>
<xsl:when test="$node/ancestor-or-self::*/d:info/d:revhistory/d:revision[last()]/d:date">
<xsl:value-of select="normalize-space(string($node/ancestor-or-self::*/d:info/d:revhistory/d:revision[last()]/d:date))"/>
</xsl:when>
<xsl:when test="$node/d:info/d:meta[@name='published']">
<xsl:value-of select="normalize-space(string($node/d:info/d:meta[@name='published']))"/>
<xsl:value-of select="normalize-space(($node/ancestor-or-self::*/d:info/d:revhistory/d:revision[last()]/d:date)[last()])"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
Expand Down Expand Up @@ -784,21 +775,33 @@
</xsl:choose>
</xsl:variable>

<!--<xsl:message>DEBUG: compare=<xsl:value-of select="$compare"/>
candidate-modified="<xsl:value-of select="$candidate-modified"/>"
<!-- <xsl:message>DEBUG:
current element=<xsl:value-of select="local-name($node)"/>
count = <xsl:value-of select="count($node/d:info/d:revhistory)"/>
compare=<xsl:value-of select="$compare"/>
candidate-modified="<xsl:value-of select="$candidate-modified"/>" / <xsl:value-of select="normalize-space($node/d:info/d:revhistory/d:revision[1]/d:date)"/>
candidate-published="<xsl:value-of select="$candidate-published"/>"
modified=<xsl:value-of select="$date-modified"/> => <xsl:value-of select="$is-modified-valid"/>
published=<xsl:value-of select="$date-published"/> => <xsl:value-of select="$is-published-valid"/>
<xsl:text>&#10;</xsl:text>
<xsl:value-of select="$date-published"/> => <xsl:call-template name="validate-date">
<xsl:with-param name="date" select="$date-modified"></xsl:with-param>
</xsl:call-template>
</xsl:message>-->

<!-- TODO: compare the two dates
</xsl:message>
-->
<!-- TODO: compare the two dates
Condition: datePublished <= dateModified
-->
<xsl:choose>
<xsl:when test="count($node/ancestor-or-self::*/d:info/d:revhistory) = 0">
<xsl:call-template name="log.message">
<xsl:with-param name="level">warn</xsl:with-param>
<xsl:with-param name="context-desc">JSON-LD</xsl:with-param>
<xsl:with-param name="message">
<xsl:text>No revhistory found in your document</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:when test="$compare &lt;= 0"/><!-- This is the expected outcome. Do nothing. -->
<xsl:when test="$compare = 1">
<xsl:call-template name="log.message">
Expand Down
6 changes: 5 additions & 1 deletion trd/xhtml/chunk.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@

<xsl:param name="is.chunk" select="1"/>

</xsl:stylesheet>
<xsl:template match="/">
<xsl:apply-imports/>
<xsl:call-template name="handle-json-ld"/>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 3699d03

Please sign in to comment.