Display a reading duration
Post here questions and problems related to editing and publishing DITA content.
Display a reading duration
Hello!
I'm looking a way to display the reading duration for a topic.
Currently, my best lead is an XSLT shared in this forum that displays the number of words contained in a map.
However, what I don't get is how I could insert the results in the first topic of the map, as a kind of infoblock.
Also, having the number of words is a good basis, but it should be necessary to proceed some calculation. I found this nice little js function which provides a rough estimation based on a word per minute.
Is there any way to apply such a function with xslt?
Has someone in the forum already met this need?
Any feedback is welcome. I recognize I was surprise nit seeing any plugin developed for that.
I'm looking a way to display the reading duration for a topic.
Currently, my best lead is an XSLT shared in this forum that displays the number of words contained in a map.
Code: Select all
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="/">
<counts>
<xsl:apply-templates/>
</counts>
</xsl:template>
<xsl:template match="text()"/>
<xsl:template match="*[contains(@class, 'map/map')]">
<xsl:variable name="text">
<xsl:apply-templates mode="getText" select="node()"/>
</xsl:variable>
<count>
<xsl:value-of
select="count(tokenize(lower-case($text), '(\s|[,.!:;]|[n][b][s][p][;])+')[string(.)])"/>
</count>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*[contains(@class, 'map/map')]" mode="getText"/>
</xsl:stylesheet>
Also, having the number of words is a good basis, but it should be necessary to proceed some calculation. I found this nice little js function which provides a rough estimation based on a word per minute.
Code: Select all
function readingTime() {
const text = document.getElementById("article").innerText;
const wpm = 225;
const words = text.trim().split(/\s+/).length;
const time = Math.ceil(words / wpm);
document.getElementById("time").innerText = time;
}
readingTime();
Has someone in the forum already met this need?
Any feedback is welcome. I recognize I was surprise nit seeing any plugin developed for that.
-
- Posts: 529
- Joined: Thu May 02, 2019 2:32 pm
Re: Display a reading duration
Post by chrispitude »
Hi gbv34,
Do you want this for PDF or HTML5 output, or both? This might influence how the implementation would work.
Do you want this for PDF or HTML5 output, or both? This might influence how the implementation would work.
-
- Posts: 529
- Joined: Thu May 02, 2019 2:32 pm
Re: Display a reading duration
Post by chrispitude »
Hi gbv34,
How would you want it annotated to the HTML output? Is there a specific HTML structure you would want?
Maybe just as a proof of concept, I could put the information in an HTML <abstract> element?
- Chris
How would you want it annotated to the HTML output? Is there a specific HTML structure you would want?
Maybe just as a proof of concept, I could put the information in an HTML <abstract> element?
- Chris
Re: Display a reading duration
Hi again 
Actually, I don't have a specific requirement for that but I thought it would be more relevant to place it close to the main heading in a topic, right after the opening of the <body> element.

Actually, I don't have a specific requirement for that but I thought it would be more relevant to place it close to the main heading in a topic, right after the opening of the <body> element.
Return to “DITA (Editing and Publishing DITA Content)”
Jump to
- Oxygen XML Editor
- ↳ Announcements
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML Services Market
- ↳ Offer a Service