Skip to content

Commit

Permalink
Fix some JSON-LD problems
Browse files Browse the repository at this point in the history
* No JSON-LD was generated for SBP & TRD
* Simplify XPath for extracting revhistory
  • Loading branch information
tomschr committed May 8, 2024
1 parent f4eb3c4 commit 63298b4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 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>
31 changes: 17 additions & 14 deletions suse2022-ns/xhtml/json-ld.xsl
Original file line number Diff line number Diff line change
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>-->
</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 63298b4

Please sign in to comment.