Add revised and modified date information within topic body
Post here questions and problems related to editing and publishing DITA content.
Add revised and modified date information within topic body
Hello, everyone!
I want to insert right after the main topic title the revised and modified dates values accessible from the critdates element (btw, it's for an HTML5 transtype and I have a dedicated plugin).
I want to apply my xslt to an existing template (based on the class topic/body), but I noticed two inconsistencies:
1. the created date attribute is applied for every topic even when there is no critdates declaration in it
2. the @date attribute value that is inserted in every topic is repeated whereas several topics have different dates declared...
For now, my xslt uses this declaration:
Would you have any idea of the problem?
I want to insert right after the main topic title the revised and modified dates values accessible from the critdates element (btw, it's for an HTML5 transtype and I have a dedicated plugin).
I want to apply my xslt to an existing template (based on the class topic/body), but I noticed two inconsistencies:
1. the created date attribute is applied for every topic even when there is no critdates declaration in it
2. the @date attribute value that is inserted in every topic is repeated whereas several topics have different dates declared...
- image.png (16.11 KiB) Viewed 641 times
- image.png (18.13 KiB) Viewed 641 times
Code: Select all
<xsl:template match="*[contains(@class, ' topic/body ')]" name="topic.body">
<!-- Here is my declaration for critdates -->
<div>
<xsl:choose>
<xsl:when test="*/critdates/created/@date > 0">
Date of creation:
<xsl:value-of select="/concept/prolog/critdates/created/@date"/>
</xsl:when>
<xsl:otherwise>Error:
<xsl:value-of select="/concept/prolog/critdates/created/@date"/>
</xsl:otherwise>
</xsl:choose>
</div>
<div>
<xsl:call-template name="commonattributes"/>
<xsl:call-template name="setidaname"/>
<xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
<xsl:apply-templates select="preceding-sibling::*[contains(@class, ' topic/abstract ')]" mode="outofline"/>
<xsl:apply-templates select="preceding-sibling::*[contains(@class, ' topic/shortdesc ')]" mode="outofline"/>
<xsl:apply-templates select="following-sibling::*[contains(@class, ' topic/related-links ')]" mode="prereqs"/>
<xsl:apply-templates/>
<xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
</div>
</xsl:template>
------
Gaspard
Gaspard
Re: Add revised and modified date information within topic body
Hi,
I did something similar for the Oxygen XML Blog, display the Author and created dates in the HTML output and then use them to create a what's new list and an RSS feed:
https://blog.oxygenxml.com/topics/recen ... _list.html
https://blog.oxygenxml.com/topics/rss_f ... ation.html
I did that as part as a Webhelp publishing template but the XSLT code should be usable in a plain HTML plugin:
https://github.com/oxygenxml/blog/blob/ ... prolog.xsl
About your questions:
An XPath like this "/concept/prolog/critdates/created/@date" is an absolute xpath, it matches the root "/concept" element and navigates down on it.
Your template matches a "body" element, so you should focus on its previous "prolog" sibling.
So maybe something like:
Also this condition preceding-sibling::prolog/critdates/created/@date > 0 I do not consider it appropriate, the date is a string with the pattern "YYYY-MM-DD": https://www.oxygenxml.com/dita/1.3/spec ... dates.html
Comparing a string with an integer value (0) does not make sense.
Regards,
Radu
I did something similar for the Oxygen XML Blog, display the Author and created dates in the HTML output and then use them to create a what's new list and an RSS feed:
https://blog.oxygenxml.com/topics/recen ... _list.html
https://blog.oxygenxml.com/topics/rss_f ... ation.html
I did that as part as a Webhelp publishing template but the XSLT code should be usable in a plain HTML plugin:
https://github.com/oxygenxml/blog/blob/ ... prolog.xsl
About your questions:
How about if you add an xsl:if around that <div> element? Something like:1. the created date attribute is applied for every topic even when there is no critdates declaration in it
Code: Select all
<xsl:if test="*/critdates">
<div>
<xsl:choose>
....
</div>
</xsl:if>
You mean in the same topic file you have several inner topics, concepts, right?2. the @date attribute value that is inserted in every topic is repeated whereas several topics have different dates declared...
An XPath like this "/concept/prolog/critdates/created/@date" is an absolute xpath, it matches the root "/concept" element and navigates down on it.
Your template matches a "body" element, so you should focus on its previous "prolog" sibling.
So maybe something like:
Code: Select all
<xsl:if test="preceding-sibling::prolog/critdates">
<div>
<xsl:choose>
<xsl:when test="preceding-sibling::prolog/critdates/created/@date > 0">
Date of creation:
<xsl:value-of select="preceding-sibling::prolog/critdates/created/@date"/>
</xsl:when>
<xsl:otherwise>Error:
<xsl:value-of select="preceding-sibling::prolog/critdates/created/@date"/>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:if>
Comparing a string with an integer value (0) does not make sense.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Re: Add revised and modified date information within topic body
One more thing, you can also do stuff like:
That <xsl:next-match/> will call the base xsl:template which matches the same element and thus you avoid copying from the base template this part of content:
Code: Select all
<xsl:template match="*[contains(@class, ' topic/body ')]" name="topic.body">
<!-- Here is my declaration for critdates -->
<div>
.....
</div>
<xsl:next-match/>
</xsl:template>
Code: Select all
<div>
<xsl:call-template name="commonattributes"/>
<xsl:call-template name="setidaname"/>
<xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
<xsl:apply-templates select="preceding-sibling::*[contains(@class, ' topic/abstract ')]" mode="outofline"/>
<xsl:apply-templates select="preceding-sibling::*[contains(@class, ' topic/shortdesc ')]" mode="outofline"/>
<xsl:apply-templates select="following-sibling::*[contains(@class, ' topic/related-links ')]" mode="prereqs"/>
<xsl:apply-templates/>
<xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
</div>
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Re: Add revised and modified date information within topic body
Hello, Radu!
Thanks a lot! That helped a lot, indeed. More particularly using the xsl:next-match to avoid copy-pasting all the previous declarations.
I also figured out why the date remained the same whatever the topic is: the map included a critdates element in its topicmeta. Therefore, the critdates declared at the map level inherits at the topic level. Removing it and declaring individual values for topics displayed a different date for each one.
I guess I have to set a condition to check if there's already a value declared in the topicmeta.
Thanks a lot! That helped a lot, indeed. More particularly using the xsl:next-match to avoid copy-pasting all the previous declarations.
I also figured out why the date remained the same whatever the topic is: the map included a critdates element in its topicmeta. Therefore, the critdates declared at the map level inherits at the topic level. Removing it and declaring individual values for topics displayed a different date for each one.
I guess I have to set a condition to check if there's already a value declared in the topicmeta.
------
Gaspard
Gaspard
Return to “DITA (Editing and Publishing DITA Content)”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ 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
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service