Can I include specific HTML fragment files in XSLT templates?
Having trouble installing Oxygen XML WebHelp? Got a bug to report? Post it all here.
-
- Posts: 907
- Joined: Thu May 02, 2019 2:32 pm
Can I include specific HTML fragment files in XSLT templates?
Post by chrispitude »
WebHelp topic pages have a "right tools" group that contains various topic-related tools (collapse, previous/next topic, print, etc.):
I would like to add my own tool to this group in a WebHelp publishing template, and I would like to use an HTML fragment so I can use macro evaluation. So, I created an XSLT file that calls <whc:include_html> with a specific @href path:
but the @href path is interpreted as HTML content to insert directly:
But if I define and use my own (nonstandard) fragment parameter:
then it works as desired.
Is there a trick to directly specifying a fragment filename with the @href attribute of a <whc:include> element? Or is this unsupported and fragments must be specified through the fragment parameter framework? I can use the nonstandard parameter approach, but if a simpler solution exists, I should use it.
A testcase is included:
To run,
1. Publish all deliverables in "project.xml".
2. Explore the WebHelp results in out/good/ (which uses a parameter) and out/bad/ (which uses a specified file path).
- image.png (7.6 KiB) Viewed 876 times
I would like to add my own tool to this group in a WebHelp publishing template, and I would like to use an HTML fragment so I can use macro evaluation. So, I created an XSLT file that calls <whc:include_html> with a specific @href path:
Code: Select all
<!-- evaluate our own fragment placeholder at the end -->
<xsl:variable name="my-tool-placeholder">
<whc:include_html href="../html-fragments/my-tool.xhtml"/>
</xsl:variable>
<xsl:apply-templates select="$my-tool-placeholder" mode="copy_template"/>
- image.png (2.55 KiB) Viewed 876 times
But if I define and use my own (nonstandard) fragment parameter:
Code: Select all
<!-- evaluate our own fragment placeholder at the end -->
<xsl:variable name="my-tool-placeholder">
<whc:include_html href="{'${webhelp.fragment.my.tool}'}"/>
</xsl:variable>
<xsl:apply-templates select="$my-tool-placeholder" mode="copy_template"/>
Is there a trick to directly specifying a fragment filename with the @href attribute of a <whc:include> element? Or is this unsupported and fragments must be specified through the fragment parameter framework? I can use the nonstandard parameter approach, but if a simpler solution exists, I should use it.
A testcase is included:
- webhelp_specific_fragment_file.zip
- (9.61 KiB) Downloaded 109 times
To run,
1. Publish all deliverables in "project.xml".
2. Explore the WebHelp results in out/good/ (which uses a parameter) and out/bad/ (which uses a specified file path).
-
- Posts: 495
- Joined: Wed Oct 16, 2019 3:47 pm
Re: Can I include specific HTML fragment files in XSLT templates?
Post by julien_lacour »
Hi Chris,
Actually this is possible to insert the fragment by referring it directly, you just need to give an additional parameter to the called template, like this:
If you take a look at com.oxygenxml.webhelp.responsive\xsl\template\commonComponentsExpander.xsl you will see that the template for whc:include_html needs the template_base_uri param (<xsl:param name="template_base_uri" tunnel="yes"/>).
The only thing to do is to get the 'webhelp.publishing.template' transformation parameter, convert it as an URI and send it to the template.
Once the base uri is resolved the href can correctly be expanded, just make sure to change the href value: it must be relative to the template folder!
Regards,
Julien
Actually this is possible to insert the fragment by referring it directly, you just need to give an additional parameter to the called template, like this:
Code: Select all
<!-- evaluate our own fragment placeholder at the end -->
<xsl:variable name="my-tool-placeholder">
<whc:include_html href="html-fragments/my-tool.xhtml"/>
</xsl:variable>
<xsl:variable name="webhelp-template-base-uri">
<xsl:value-of select="concat('file:/', replace(oxygen:getParameter('webhelp.publishing.template'), '\\', '/'), '/')"/>
</xsl:variable>
<xsl:apply-templates select="$my-tool-placeholder" mode="copy_template">
<xsl:with-param name ="template_base_uri" select="$webhelp-template-base-uri" tunnel="yes"/>
</xsl:apply-templates>
The only thing to do is to get the 'webhelp.publishing.template' transformation parameter, convert it as an URI and send it to the template.
Once the base uri is resolved the href can correctly be expanded, just make sure to change the href value: it must be relative to the template folder!
Regards,
Julien
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