Change date style of APA MS Word bibliography - xslt

I am writing my thesis and my professor wants me to use the APA style. Here I have the problem, that it shows dates like this "DD. MM YYYY" However, I want it to be "DD.MM.YYYY".
Somehow it not only uses spaces in general, there is this single dot after the date. This means it is not a style I dont generylly like, but it seems to be buggy. Why?
I have looked through the xls file but just cannot find the exact problem. In the Harvard xml, it was easy because i just needed to change "spaces" to "dot"-templates. Here, however, they seem to use a recursive style and I have no clue, where I need to make changes.
I would very grateful if anyone could help me!
I use office365, and I tried changing the xls I found at C:\Users\$user\AppData\Roaming\Microsoft\Bibliography\Style\APASixthEditionOfficeOnline.xsl
Here (pastebin) is the original code from the part, where I believe the "spaces" and "dots" are put.
the parameters are:
format: which is either MY or DMY (depending if day field is put or not)
day, month and year: are the data of the souce
withDot is initially not set (at least I cant find it anywhere)
I you need any further information, please let me know.
UPDATE
Here is the complete bibliography style code from Windows.
Here is the selected code with all templates that I believe are called while formatting the date(s).

It's not possible to reproduce the problem from what you posted, mainly because the template you refer to requires other templates.
In any case, if all you need is to produce two different formats of date, you could do this much more simply by:
<xsl:template name="formatDate">
<xsl:param name="day"/>
<xsl:param name="month"/>
<xsl:param name="year"/>
<xsl:param name="format" />
<xsl:choose>
<xsl:when test="$format='DMY'">
<xsl:value-of select="format-number($day, '00.')"/>
<xsl:value-of select="format-number($month, '00.')"/>
<xsl:value-of select="$year"/>
</xsl:when>
<xsl:when test="$format='MY'">
<xsl:value-of select="format-number($month, '00.')"/>
<xsl:value-of select="$year"/>
</xsl:when>
<xsl:otherwise>??</xsl:otherwise>
</xsl:choose>
</xsl:template>
Examples of calling the template:
call:
<date>
<xsl:call-template name="formatDate">
<xsl:with-param name="format" select="'DMY'"/>
<xsl:with-param name="day" select="5"/>
<xsl:with-param name="month" select="3"/>
<xsl:with-param name="year" select="2014"/>
</xsl:call-template>
</date>
returns:
<date>05.03.2014</date>
call:
<date>
<xsl:call-template name="formatDate">
<xsl:with-param name="format" select="'MY'"/>
<xsl:with-param name="month" select="7"/>
<xsl:with-param name="year" select="1876"/>
</xsl:call-template>
</date>
returns:
<date>07.1876</date>

Related

XSLT How to use substring-after and concate multiple times for one string

I have a little problem and I just can't seem to figure it out. I have a RTF string in an XML and want to cut out images there. That works so far. But now I have the problem that the string is only checked and shortened once. But there can be between 0 and infinite images attached. I do not understand how I can replace all of them, i.e. execute concat several times.
Thanks so much for your help
XML File:
https://pastebin.com/6iVuFasn
My XSL Code:
<xsl:variable name="storyFormattedText" select="//STORY_TEXT_RTF"/>
<xsl:variable name="textWithoutImages">
<xsl:value-of select="$storyFormattedText"/>
<xsl:if test="contains($storyFormattedText,'{\result{\pict{\*\picprop}')">
<xsl:value-of select="concat(substring-before($storyFormattedText,'{\result{\pict{\*\picprop}'),substring-after($storyFormattedText,'}}}'))"/>
</xsl:if>
</xsl:variable>
<xsl:call-template name="create_field">
<xsl:with-param name="field_id">15</xsl:with-param>
<xsl:with-param name="field_type">1</xsl:with-param>
<xsl:with-param name="field_name">Formatted Text ohne Bilder</xsl:with-param>
<xsl:with-param name="is_empty">no</xsl:with-param>
<xsl:with-param name="value">
<xsl:value-of select="concat(substring-before($storyFormattedText,'{\result{\pict{\*\picprop}'),substring-after($storyFormattedText,'}}}'))"/>
</xsl:with-param>
</xsl:call-template>

How to replace variable inside curly braces with values in different tags in xslt

I am processing an xml file using xslt.
<ns1:declarationStatements>
<ns1:parameterisedEntity>
<ns2:code>NUTSUPSTATE20</ns2:code>
<ns2:localeData>
<ns1:description>
<![CDATA[** When {s} according to instructions {m}g typically weighs {m}g.]]>
</ns1:description>
<ns1:id>20253</ns1:id>
</ns2:localeData>
<ns2:specType>FOOD</ns2:specType>
<ns2:id>6653</ns2:id>
</ns1:parameterisedEntity>
<ns1:textParameters>
<ns1:value>228</ns1:value>
<ns1:id>68225</ns1:id>
<ns1:sequence>2</ns1:sequence>
</ns1:textParameters>
<ns1:textParameters>
<ns1:value>cooked</ns1:value>
<ns1:id>68233</ns1:id>
<ns1:sequence>0</ns1:sequence>
</ns1:textParameters>
<ns1:textParameters>
<ns1:value>255</ns1:value>
<ns1:id>68229</ns1:id>
<ns1:sequence>1</ns1:sequence>
</ns1:textParameters>
<ns1:id>133421</ns1:id>
</ns1:declarationStatements>
I want to get the text inside <ns1:description> i.e.-
**When {s} according to instructions {m}g typically weighs {m}g
But I want {s}, {m} and {m} to be replaced by the values in <ns1:textParameters>/<ns1:value>. It should look like -
**When cooked according to instructions 255g typically weighs 228g.
I tried doing that by using <xsl:value-of select="ns0:declarationStatements"> and the manipulating string but it is becoming very tedious and complex.
The number of such braces may also vary. So do we have anything like List or Array in XSLT?
Is there any other way or trick I can use to solve this problem?
Thanks
Assuming the parameters are meant to be inserted in order of their ns1:sequence value, I would start by defining a key as:
<xsl:key name="text-param" match="ns1:textParameters" use="ns1:sequence" />
then call the following recursive template with ns1:description as the string param:
<xsl:template name="merge-params">
<xsl:param name="string"/>
<xsl:param name="i" select="0"/>
<xsl:choose>
<xsl:when test="contains($string, '{') and contains(substring-after($string, '{'), '}')">
<xsl:value-of select="substring-before($string, '{')" />
<xsl:value-of select="key('text-param', $i)/ns1:value" />
<!-- recursive call -->
<xsl:call-template name="merge-params">
<xsl:with-param name="string" select="substring-after($string, '}')" />
<xsl:with-param name="i" select="$i + 1" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

How do you get DocBook XSL's chunking to generate a full TOC for each page?

I have a bunch of DocBook XML files that all get merged into a single DocBook file for conversion into HTML. Each individual document is a reference page (for a function or similar construct). I use chunked HTML generation, so that each reference page becomes its own HTML page.
The problem is this: I want a table of contents on each page. But I don't want the table of contents for that page. I want the full TOC for the entire reference manual.
That is, from any page, I want to be able to jump to any other page by using the TOC. I can use CSS styling to stick the TOC on the left side (and even hide it for mobile viewing or whatever).
There's an obvious way to handle this. I could extract the main TOC via a post-process script and have the script copy this into each of the output HTML documents. What I'm looking for is a way to do it that works within DocBook XSL.
I want the results to look rather like DocBook XSL's newer webhelp, but with less overt JavaScript involvement.
As of 2019-07-06 with docbook-xsl-1.79.2 the currently accepted answer isn't sufficient to make each table of contents complete.
The following XSL template does, however. The key insight was stepping through with the Oxygen XML editor's debugger and noticing that while the toc-context was correctly set to the root element, the nodes variable was still the local subset.
I undid the toc-context change. Instead I created a new variable root-nodes selecting /, and edited the make.toc template to use root-nodes instead of nodes.
Putting this in my customisation layer now makes every table of contents a complete table of contents.
<xsl:template name="make.toc">
<xsl:param name="toc-context" select="."/>
<xsl:param name="toc.title.p" select="true()"/>
<xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
<xsl:variable name="root-nodes" select="/"/>
<xsl:variable name="nodes.plus" select="$root-nodes | d:qandaset"/>
<xsl:variable name="toc.title">
<xsl:if test="$toc.title.p">
<xsl:choose>
<xsl:when test="$make.clean.html != 0">
<div class="toc-title">
<xsl:call-template name="gentext">
<xsl:with-param name="key">TableofContents</xsl:with-param>
</xsl:call-template>
</div>
</xsl:when>
<xsl:otherwise>
<p>
<strong>
<xsl:call-template name="gentext">
<xsl:with-param name="key">TableofContents</xsl:with-param>
</xsl:call-template>
</strong>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:variable>
<xsl:choose>
<xsl:when test="$manual.toc != ''">
<xsl:variable name="id">
<xsl:call-template name="object.id"/>
</xsl:variable>
<xsl:variable name="toc" select="document($manual.toc, .)"/>
<xsl:variable name="tocentry" select="$toc//d:tocentry[#linkend=$id]"/>
<xsl:if test="$tocentry and $tocentry/*">
<div class="toc">
<xsl:copy-of select="$toc.title"/>
<xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
<xsl:call-template name="toc.list.attributes">
<xsl:with-param name="toc-context" select="$toc-context"/>
<xsl:with-param name="toc.title.p" select="$toc.title.p"/>
<xsl:with-param name="nodes" select="$root-nodes"/>
</xsl:call-template>
<xsl:call-template name="manual-toc">
<xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
</xsl:call-template>
</xsl:element>
</div>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$qanda.in.toc != 0">
<xsl:if test="$nodes.plus">
<div class="toc">
<xsl:copy-of select="$toc.title"/>
<xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
<xsl:call-template name="toc.list.attributes">
<xsl:with-param name="toc-context" select="$toc-context"/>
<xsl:with-param name="toc.title.p" select="$toc.title.p"/>
<xsl:with-param name="nodes" select="$root-nodes"/>
</xsl:call-template>
<xsl:apply-templates select="$nodes.plus" mode="toc">
<xsl:with-param name="toc-context" select="$toc-context"/>
</xsl:apply-templates>
</xsl:element>
</div>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$root-nodes">
<div class="toc">
<xsl:copy-of select="$toc.title"/>
<xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
<xsl:call-template name="toc.list.attributes">
<xsl:with-param name="toc-context" select="$toc-context"/>
<xsl:with-param name="toc.title.p" select="$toc.title.p"/>
<xsl:with-param name="nodes" select="$root-nodes"/>
</xsl:call-template>
<xsl:apply-templates select="$root-nodes" mode="toc">
<xsl:with-param name="toc-context" select="$toc-context"/>
</xsl:apply-templates>
</xsl:element>
</div>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Note: there is a remaining issue where not every chunked page gets its own ToC, but that is unrelated to this specific. If I sort it, I'll add a comment on how I did that.
There’s a relatively easy way to get that, though I’m pretty sure you can’t without either creating a DocBook XSL customization layer or just directly modifying the installed (system) stylesheets.
Either way, I think the actual docbook-xsl template you need to modify or override is named make.toc, located in the stylesheets distribution in the file html/autotoc.xsl.
It’s a big template—nearly a hundred lines—but you only need to make a one-line change to it:
--- /usr/share/xml/docbook/stylesheet/docbook-xsl/html/autotoc.xsl 2012-12-16 11:35:12.000000000 +0900
+++ /opt/workspace/autotoc.xsl 2015-12-26 09:19:36.000000000 +0900
## -28,7 +28,7 ##
</xsl:variable>
<xsl:template name="make.toc">
- <xsl:param name="toc-context" select="."/>
+ <xsl:param name="toc-context" select="/"/>
<xsl:param name="toc.title.p" select="true()"/>
<xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
That is, you need to call that template with the toc-context param set to "/" (instead of ".").
The default "." value tells the template that, when creating a TOC for a chunk, it should only look at the (child) content of whatever element it’s currently processing (that is, the root of that particular chunk); for example, if it’s processing a section it looks only at the children of that section.
But if you instead change that value to "/", you’re telling the template to (re)look at the entire content of the source document each time. So if your document is a book, it’ll give you the entire TOC for the whole book each time, or if your document is an article, the entire article, etc.
So I think that should give you what you’re wanting.
If you decide to just modify the installed stylesheets and you’ve installed them from any OS-specific package manager you use, you need to find where the html/autotoc.xsl file is installed.
On my Debian Linux system the html/autotoc.xsl file is here:
/usr/share/xml/docbook/stylesheet/docbook-xsl/html/autotoc.xsl
And on my OS X system, installed from a homebrew package, it’s here:
/usr/local/opt/docbook-xsl/docbook-xsl/html/autotoc.xsl
If you decide to instead create a customization layer, you’ll need to copy that entire make.toc template into your customization layer (but with that toc-context param changed to "/").

how can i add spaces generic way by passing parameter using XSLT

is any way to create function create wanted spaces in the output, because i was keep hot coding were ever i required space <xsl:text>
</xsl:text >, kindly suggest a function to generate a space based on the passed parameter,please advice
You may be looking at recursive template. Something like this:
<xsl:template name="WriteSpaces">
<xsl:param name="count" />
<xsl:if test="$count > 0">
<xsl:text> </xsl:text>
<xsl:call-template name="WriteSpaces">
<xsl:with-param name="count" select="$count - 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>
Notice that invoking this would actually pollute your code even more than just putting spaces directly. For static content I would probably just use text. For dynamic content (i.e. if you want <xsl:text> </xsl:text><xsl:value-of select="." /><xsl:text> </xsl:text>) I would use concat() function as it does not limit the number of parameters - so you could code above just as <xsl:value-of select="concat(' ', ., ' ')" />.

XSL variable seems to be returning null

I have the following XSL file from the DCM4CHEE DICOM project and I was trying to adjust it slightly. The code I'm actually trying to get working is commented out, but even the variable assignment seems to actually be returning null. The DCM4CHEE logs are throwing Java exceptions with a 'null' seeming to be coming from the XSL template when it compiles it.
<xsl:call-template name="attr">
<xsl:with-param name="tag" select="'00100040'"/>
<xsl:with-param name="vr" select="'CS'"/>
<xsl:variable name="testing" select="string(field[8]/text())" />
<xsl:with-param name="val" select="$testing" />
<!--
<xsl:variable name="sexString" select="string(field[8]/text())" />
<xsl:variable name="sex">
<xsl:choose>
<xsl:when test="$sexString='1'">M</xsl:when>
<xsl:when test="$sexString='2'">F</xsl:when>
<xsl:when test="$sexString='9'">U</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$sexString"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:with-param name="val" select="$sex" /> -->
</xsl:call-template>
The normal XSL is just one simple line:
<xsl:with-param name="val" select="string(field[8]/text())" />
I'm probably doing something very wrong, but can someone explain why I'm not able to assign field[8]/text() to a variable and then pass it to the with-param?
<xsl:call-template name="attr">
<xsl:with-param name="tag" select="'00100040'"/>
<xsl:with-param name="vr" select="'CS'"/>
<xsl:variable name="testing" select="string(field[8]/text())" />
<xsl:with-param name="val" select="$testing" />
</xsl:call-template>
I'm probably doing something very wrong, but can someone explain why
I'm not able to assign field[8]/text() to a variable and then pass it
to the with-param?
Yes, the code is so wrong that the XSLT processor should throw an error message without compiling/executing it.
According to the W3C XSLT 1.0 specification, the only allowed element as child of xsl:call-template is xsl:with-param.
The presented code clearly violates this syntactic rules by placing other elements (xsl:variable) as children of xsl:call-template).
Solution: Move the variables out (before) the xsl:call-template:
<xsl:variable name="testing" select="string(field[8]/text())" />
<xsl:call-template name="attr">
<xsl:with-param name="tag" select="'00100040'"/>
<xsl:with-param name="vr" select="'CS'"/>
<xsl:with-param name="val" select="$testing" />
</xsl:call-template>
The code above is syntactically correct.