DITA Open Toolkit CHM (HTML Help Workshop) output - xslt

I use the DITA Open Toolkit to convert my DITA files into CHM (HTML Help Worskhop) and tocjs (HTML) format.
I need to copy the content of 1 topic into all the others topics of my map (like a header file for example).
I tested to create a header template :
<xsl:template name="ShortDescriptionTemplate">
<p class="Dx:ShortDescription">
<!--<xsl:apply-templates select="*[contains(#class,' topic/shortdesc ')]"/>-->
<xsl:variable name="shortDv1"><xsl:apply-templates select="shortdesc"/></xsl:variable>
<xsl:value-of select="normalize-space($shortDv1)"/>
</p><xsl:value-of select="$newline"/>
</xsl:template>
<xsl:template match="/|node()|#*" mode="gen-user-header">
<div id="header">
<xsl:if test="contains(#class,' topic/topic ')">
<xsl:text>Bonjour 1</xsl:text><!-- Works!!! Displays on all topics -->
<xsl:call-template name="ShortDescriptionTemplate"/>
<!-- Doesn't Works!!! Displays on my shortdesc topic but nothing in the others topics-->
<xsl:copy-of select="shortdesc"/> <!-- nothing in the others topics-->
</div>
</xsl:template>
Someone to help me ?
Thanks,

See the documentation at http://dita-ot.sourceforge.net/1.6/
I don't use the latest version, but as recently as 1.6, you could set up a running header by using the parameter "args.hdr". Might be the same on the new one. See the topic on Ant parameters.
If you want to go another route you could use #conref. See " content inclusion" in the DITA specification at http://docs.oasis-open.org/dita/v1.2/os/spec/DITA1.2-spec.html

Related

Xslt: populate innertext value of <a href="" /> in xslt during runtime

I tried a lot to see if any suggestion/answer would satisfy my requirement but could not find any.
I have an Xml file which I am using to get an output Html file using XslTransform API and an Xslt stylesheet.
My xml file has a rootnode which will have two attributes - HyperlinkDisplayText and HyperlinkValue. This xml file is generated at runtime. So, the values of these attributes are not known at compile time.
My requirement is that the html output should display a hyperlink whose display text needs to be taken from the value of 'HyperlinkDisplayText' and the hyperlink value needs to be taken from the value of "HyperlinkValue'.
For example,
<RootNode HyperlinkDisplayText="Google" HyperlinkValue="https://www.google.com/" />
This needs to be appears as Google.
For this, I tried several things in my xslt. Below is a snapshot what I am trying in my xslt file -
<xsl:choose>
<xsl:when test="#HyperlinkDisplayText and #HyperlinkValue">
<h4 style="font-family: arial" align='center'>
#HyperlinkDisplayText
</h4>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
It is not working. Any help is highly appreciated.
Regards,
kvk938
Change #HyperlinkDisplayText to <xsl:value-of select="#HyperlinkDisplayText"/>. That assumes the context node is a RootNode element.

umbraco: get USER properties, NOT member properties in XSLT

Here's my scenario:
Added an Author Picker to the default umbBlogPost (from the blog4umbraco package) which gives me access to the author's id in an XSLT macro
The Author Picker is pulling up a list of umbraco users, not members
I want to the display the author's username in xslt output
I've tried several different ways based on Google searches which all seem to be using the Membership API, such as umbraco.libary:GetMember and umbraco.library:GetMemberName which is not working, again, as I am dealing with umbraco users, not members. There doesn't appear to be any user equivalent methods, i.e., umbraco.libary:GetUser or umbraco.library:GetUserName.
Does anyone know how I can get user properties in an xslt macro? I am using version 4.7.2. Also, while I'm currently working with xslt, if this can be done with a Razor macro (if supported in 4.7.2?) I am open to seeing this approach as well. Thanks.
Taking a look directly in the XML that the XSLTs run off (~/App_Data/umbraco.config), I found the following attributes:
<Site
writerID="0"
creatorID="0"
writerName="John Smith"
creatorName="John Smith"
/>
So you should be able to reference those in the XSLT with the following:
<xsl:value-of select="$currentPage/#writerName" />
If you need the other properties of the user, you'll probably need to write your own library, which could then be accessed by the XSLT files. Just look at how umbraco.library is included at the top of the file.
Ucomponents provides an XSLT solution
<xsl:choose>
<xsl:when test="$currentPage/bodyAuthor != ''">
<xsl:value-of select="ucomponents.cms:GetUserName($currentPage/bodyAuthor)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$currentPage/#writerName" />
</xsl:otherwise>
</xsl:choose>
I ended up solving this by writing a Razor macro. The key was to add #using umbraco.BusinessLogic; at the beginning of the macro. This namespace provides the API required to get user data as opposed to member data.
For anyone interested, here's the macro I wrote:
#using umbraco.BusinessLogic;
#inherits umbraco.MacroEngines.DynamicNodeContext
<div>
<h1>
From Our Blog
</h1>
<ul>
#foreach(var i in #Model.AncestorOrSelf("umbHomepage").Descendants("umbBlogPost").OrderBy("PostDate desc").Take(5))
{
<li>
<p>
#i.Name<br />
by #umbraco.BusinessLogic.User.GetUser(Int32.Parse(i.blogAuthor)).Name on #i.PostDate.ToString("MMM dd, yyyy")
</p>
</li>
}
</ul>
</div>

How to dynamically assign name and href for anchor tag in xsl

I have a requirement where the xml might have one or more services (name might be different), and I am having a content which should have all of these available services from the xml something like below
<li>CMS</li>
<li>DIS</li>
but above I have hardcoded the a tag content and href since I know these are the values, but in real time I would not be knowing these names, so how to set href and anchor tag contents based on xml values?
So far I got the below for-each statement, which gets me all the service names from the xml
<xsl:variable name="number">
<xsl:number/>
</xsl:variable>
<xsl:for-each select="csmclient/product/domainmetadata/domainmetadata_service">
<li><xsl:value-of select="#name"/><xsl:value-of select="position()"/></li>
</xsl:for-each>
.
.
.
<!--far below end-->
<xsl:for-each select="domainmetadata/domainmetadata_service">
<h3>Service Name: <span style="color:#328aa4"><a name="_ser{$number}" href="#_top"><xsl:value-of select="#name"/></a></span></h3>
.
.
.
</xsl:for-each>
but it does not seem to work, it gives me all my services but the link does not work. Any other ideas?
Note: I took help from this question link which had a similar requirement.
There is a xslt function generate-id() which gives and unique textual identifier for any node in the xml.
http://www.w3.org/TR/xslt#function-generate-id
Use something like below, should work
<xsl:for-each select="csmclient/product/domainmetadata/domainmetadata_service">
<li><xsl:value-of select="#name"/></li>
</xsl:for-each>
<xsl:for-each select="domainmetadata/domainmetadata_service">
<h3>Service Name: <span style="color:#328aa4"><a name="{generate-id()}" href="#_top"><xsl:value-of select="#name"/></a></span></h3>
</xsl:for-each>
<li><xsl:value-of select="#name"/><xsl:value-of select="position()"/></li>
but it does not seem to work ...
What you are trying to write is this (not discussing at all if this uniquely identifies the node):
<li>
<a href="#_ser{$number}{#name}{position()}"/>
</li>

How do I select all comment nodes in an XML file?

Simple question. I have an XML file with a few dozens of comment blocks. This is being transformed by a stylesheet to generate an HTML page. However, the comments are ignored with this.
But at the bottom of the generated HTML I would like to have a list of all comments within the XML file. Is that even possible, without the use of anything else than pure XSLT? (No Javascript or whatever!)
As far as I know, this is not possible, but I could be wrong...
The reason the comments aren't processed is that the default template for comments do nothing:
<xsl:template match="processing-instruction()|comment()"/>
See XSLT 1.0 spec "Built-in Template Rules".
If you would like to do something else with comments, you could just create your own matching template and output them as either a new XML comment using xsl:comment or make a HTML list:
<xsl:template match="/">
<ul>
<xsl:apply-templates select="//comment()"/>
</ul>
</xsl:template>
<xsl:template match="comment()">
<li>
<xsl:value-of select="."/>
</li>
</xsl:template>

Umbraco XSLT select newsitem sub nodes regardless of currentpage

I need to say; I'm pretty green in xslt so, most likely, that's the main problem; nonetheless been on it for hours and can't get it.
I want to fill a column on my main template with the 5 most recent newsitems. These newsitems should be shown regardless of the currentpage.
I've tried this:
<xsl:template match="/">
<xsl:for-each select="umbraco.library:GetXmlNodeById(1075)/child::node">
<p>
<strong>
<xsl:value-of select="header"/>
</strong>
</p>
</xsl:for-each>
</xsl:template>
Where, at the moment, 1075 is my News template. Ive tried it with just: GetXmlNodeById(1076)/node (where 1076) is my NewsItem template. I've tried it with the node-Id's from the content-tree, but no luck..
Anyone able to help me out here? Am stuck and I've searched high and low on Google, the forums and documentation, but I'm most likely missing something vital here. TIA!
P.S. Using Umbraco 4.5 BTW
This should output current and child nodes.
<xsl:copy-of select="umbraco.library:GetXmlNodeById(1075)"/>
In Umbraco 4.5 the schema has changed, from /node[#nodeTypeAlias='News'] to /News [#isDoc]
http://blog.leekelleher.com/2010/04/02/working-with-xslt-using-new-xml-schema-in-umbraco-4-1/
So your xslt should look like
<xsl:template match="/">
<ul>
<xsl:for-each select="umbraco.library:GetXmlNodeById(1075)/News [#isDoc]">
<li><xsl:value-of select="#nodeName"/></li>
</xsl:for-each>
</ul>
</xsl:template>