injecting script tag in ditamap.html

111 views
Skip to first unread message

Prathamesh Mestry

unread,
Jul 9, 2018, 6:24:47 AM7/9/18
to DITA-OT Users
Hi Everyone,
      Please find an html file attached with this post. what is it for I'll tell you later in this post.
      I am generating html5 output and the problem that I am facing is, 
     Scenario : when the output is generated it creates a .html(lets say ditamap.html file, which links to all other topic.html files) using the .ditamap file. And there are other files too like topic.html.
     Problem statement : I want to inject a <script type="text/javascript" src="script.js"/> tag in the head tag of ditamap.html file using xsl or anything.
     
     Thank You.

Regards,
Prathamesh M.
index.html

Michael Morrison

unread,
Jul 9, 2018, 6:01:30 PM7/9/18
to DITA-OT Users
Prathamesh - 

In your Ant file for generating the HTML5 output, add an args.hdf parameter as a property for the build.xml file, for example:
<property name="args.hdf" value="${mydir}${file.separator}myheader.xml"/>
Then, in the myheader.xml file, include a <div> with your additions to the HTML header; for example:

<div>
<script type="text/javascript" src="script.js"/>
</div>

See http://www.dita-ot.org/3.1/parameters/parameters-html5.html for a description of the args.hdf parameter.

Hope that helps.

Cheers,
Michael
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Prathamesh Mestry

unread,
Jul 10, 2018, 11:40:32 AM7/10/18
to DITA-OT Users
HI Michael,
    First of all thank you, your suggestion did work for me. I have one small problem, if you could help. Please find the attached folder with this post.
    Scenario: As you can see in the folder attached, with your suggestion I am able to generate <script> in all the files that are in the taskbook folder.  
    Problem Statement : I am not able to generate <script> tag in the index.html file.
    Thank You.

Regards,
Prathamesh M.
customhtml5_1 - Copy.zip

Michael Morrison

unread,
Jul 11, 2018, 9:09:19 PM7/11/18
to DITA-OT Users
Prathamesh - 

I don't know the reason, but I think that the args.hdf (along with args.hdr and args.ftr) parameters do not modify the top-most file (the index.html file in your case, the Eclipse help TOC file, and so on) that includes the content, but only the lower-level "topic" files.  Someone who better understands the processing architecture would have to explain the why/how for this ... and if there is a way around it.

It looks like your index.html file is a table of contents for your project.  If the embedded JS is important for this file, you could create a manual TOC using <xref> elements to each topic.  This manual TOC would be a child DITA file of the top-level ditamap, and thus should get the <script> tag from the  args.hdf parameter when converted to HTML5.  Then, I think you won't need the generated index.html file anymore.

-- Michael

Stefan Eike

unread,
Jul 12, 2018, 1:28:09 AM7/12/18
to DITA-OT Users
You probably need to override a few XSL templates.

args.html5.toc
Specifies the base name of the TOC file.
args.html5.toc.class
Specifies the value of the @class attribute on the <body> element in the TOC file.
args.html5.toc.xsl
Specifies a custom XSL file to be used for TOC generation.

Prathamesh Mestry

unread,
Jul 12, 2018, 5:15:37 AM7/12/18
to DITA-OT Users
Thank You Michael, I'll try and let you know.

Regards,
Prathamesh M

Prathamesh Mestry

unread,
Jul 12, 2018, 5:28:53 AM7/12/18
to DITA-OT Users
Hi Stefan, 
             I did tried custom xsl, but I could not get it work. Let me just go through the that you shared and try it, after that I'll let you know if any updates.
             Thank You.

Regards,
Prathamesh M.
Reply all
Reply to author
Forward
0 new messages