Help with XSTL extension
Posted: Sat Jul 06, 2024 12:43 am
I've spent many hours trying to debug the extension of DITA to WebHelp Responsive that I wrote which comes up with empty results. I want to add Open Graph metadata to each page based on the metadata in that page. I followed this guide to the note, rereading it several times: https://www.oxygenxml.com/doc/versions/ ... mport.html and I am successfully adding the <meta> tags where I want them in the output, but the content is always empty and I cannot figure out why, and I'm getting horribly frustrated. Note: I have no knowledge of XSLT transformations, I'm trying to learn from scratch.
Here's a shortened version of my DITA and .xls files, where I'm trying to get out the title and shortdesc of the current file and put them into og metadata:
(but I want it to work for task/topic as well)
I've tried:
//title
/*/title
/*/*/title
/*/*:title
Nothing works, the resultant meta is always: <meta property="og:title" content=""/>
However, frustrating as it is, when I try:
$toc/title
(as in: https://www.oxygenxml.com/doc/versions/ ... mport.html)
It works, taking the title of the ditamap...
Please, help, and also maybe include an example of using values from the current DITA file instead of $toc in the documentation please?
Thank you in advance.
Here's a shortened version of my DITA and .xls files, where I'm trying to get out the title and shortdesc of the current file and put them into og metadata:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="about">
<title>Title</title>
<shortdesc>Description</shortdesc>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:whc="http://www.oxygenxml.com/webhelp/components"
exclude-result-prefixes="xs whc"
version="3.0">
<xsl:template match="*:meta[contains(@name, 'viewport')]" mode="copy_template">
<!-- I was trying to find a way to match the head element and put this inside but I could not, so I decided to put the new meta elements after one element that exists in the original template -- and this works correctly -->
<xsl:next-match/>
<xsl:element name="meta" namespace="http://www.w3.org/1999/xhtml">
<!-- I'm adding this because otherwise I had xmlns="" attributes in every meta -->
<xsl:attribute name="property">og:title</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="/*/*:title"/>
</xsl:attribute>
</xsl:element>
<xsl:element name="meta" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="property">og:description</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="/*/*:shortdesc"/>
</xsl:attribute>
</xsl:element>
<!-- there's more but if I can get these 2 to work, I feel I can get anything else to work -->
</xsl:template>
</xsl:stylesheet>
//title
/*/title
/*/*/title
/*/*:title
Nothing works, the resultant meta is always: <meta property="og:title" content=""/>
However, frustrating as it is, when I try:
$toc/title
(as in: https://www.oxygenxml.com/doc/versions/ ... mport.html)
It works, taking the title of the ditamap...
Please, help, and also maybe include an example of using values from the current DITA file instead of $toc in the documentation please?
Thank you in advance.