Add link in author label - DSpace 6.2 - xslt

I've trying to edit item-view.xsl to add a link in author label (dc.contributor.author) but no luck yet.
I'm using XMLUI - Mirage2
Author link example image
in: https://openknowledge.worldbank.org/handle/10986/29498
What should I add?
Thanks

The following code snippet might help. This code turns the subject field into a facet link. It will require a little modification to work for the author field.
<xsl:variable name="H_SUBJECT">Subject</xsl:variable>
<xsl:variable name="DFILTER_SUBJECT">/discover?filtertype=subject&filter_relational_operator=equals&filter=</xsl:variable>
<xsl:template name="itemSummaryView-DIM-subject">
<xsl:if test="dim:field[#element='subject']">
<div class="simple-item-view-description item-page-field-wrapper table">
<h5><xsl:value-of select="$H_SUBJECT"/></h5>
<div>
<xsl:for-each select="dim:field[#element='subject']">
<xsl:choose>
<xsl:when test="node()">
<a class="gu-subject-link" href="{concat($FILTER_SUBJECT,.)}">
<span>
<xsl:apply-templates select="." mode="microtag-prop"/>
<xsl:apply-templates select="text()"/>
</span>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="count(following-sibling::dim:field[#element='subject']) != 0">
<xsl:text>; </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:if test="count(dim:field[#element='subject']) > 1">
<xsl:text>; </xsl:text>
</xsl:if>
</div>
</div>
</xsl:if>
</xsl:template>

Related

Create a attribute dynamically

I'm writing an xsl script in which I need to create the attribute dynamically.
Here is my sample code.
<Table BORDERLINESTYLE="solid" BOTTOMMARGIN="12" NOTEGROUPSPACING="single" CELLPADDING="0" CELLSPACING="0" WIDTH="504"></Table>
Here BORDERLINESTYLE may or may not be available to all Table tags. and I want the output to be something like this.
<table style="border-style:solid; border-margin:12px; width:504px"></table>
Here are 2 things that I've tried.
1. Creating attributes
<table>
<xsl:if test="./#BORDERLINESTYLE">
<xsl:attribute name="border" select="'1px solid'"/>
</xsl:if>
<xsl:if test="./#WIDTH">
<xsl:attribute name="width" select="concat(./#WIDTH, 'px')"/>
</xsl:if>
<xsl:if test="./#BOTTOMMARGIN">
<xsl:attribute name="border" select="'1px solid'"/>
</xsl:if>
<xsl:apply-templates/>
</table>
the output that I get is as below.
<table border="1px solid" width="504px">
2. Inline adding
<table style="width:{current()/#WIDTH,'px'}; border:{./#BORDERLINESTYLE}; margin-bottom: {./#BOTTOMMARGIN, 'px'}; margin-top:{./#TOPMARGIN, 'px'}; "></table>
and the output is as below with some blank values like margin-top
<table style="width:504 px; border:solid; margin-bottom: 12 px; margin-top:px; ">
How can I add styles to style based on the attributes provided in the XML?
I'm using XSLT2.0.
I would use something like this:
<xsl:if test="#BORDERLINESTYLE|#WIDTH|#BOTTOMMARGIN|#TOPMARGIN">
<xsl:attribute name="style">
<xsl:if test="#BORDERLINESTYLE">
<xsl:text>border:1px solid;</xsl:text>
</xsl:if>
<xsl:if test="#WIDTH">
<xsl:value-of select="concat('width:',#WIDTH, 'px;')"/>
</xsl:if>
<xsl:if test="#BOTTOMMARGIN">
<xsl:value-of select="concat('margin-bottom:',#BOTTOMMARGIN, 'px;')"/>
</xsl:if>
<xsl:if test="#TOPMARGIN">
<xsl:value-of select="concat('margin-top:',#TOPMARGIN, 'px;')"/>
</xsl:if>
</xsl:attribute>
</xsl:if>
And depending on the business rules for mapping those source-attributes to style attributes change the code accordingly.
Btw.: ./# is the same as #
Use if else Function
For Example
margin-top: {if(//#TOPMARGIN!=0) then {./#TOPMARGIN, 'px'} else '12px'}
I need to create the attribute dynamically.
Actually, you want to populate the attribute dynamically - which could be done by applying a template to each input attribute you want to use:
<xsl:template match="Table">
<table>
<xsl:attribute name="style">
<xsl:apply-templates select="#BORDERLINESTYLE | #BOTTOMMARGIN | #WIDTH"/>
</xsl:attribute>
</table>
</xsl:template>
<xsl:template match="#BORDERLINESTYLE">
<xsl:text>border-style:</xsl:text>
<xsl:value-of select="."/>
<xsl:text>; </xsl:text>
</xsl:template>
<xsl:template match="#BOTTOMMARGIN">
<xsl:text>border-margin:</xsl:text>
<xsl:value-of select="."/>
<xsl:text>px; </xsl:text>
</xsl:template>
<xsl:template match="#WIDTH">
<xsl:text>width:</xsl:text>
<xsl:value-of select="."/>
<xsl:text>; </xsl:text>
</xsl:template>

XSL word citation change

I have found a *.xsl citation template for Word 2010. It is almost what I need I just need a few changes done.
First it shows in the output e.g. [Str17] but it should show [STR-17]
Further it shows the bibliography not in a table with a tab in between the TAG and the entry.
e.g.
looks like that
but i need
I need that format
I just can't adjust the xsl to my needs. I have been trying for a while now and trying to find any other xsl file but no luck. This kind to citation is pretty common in engineering so I am sure I am not the only one looking for a solution.
I think for the first part of my question regarding the style of the Tag the relevant code is:
<xsl:if test="msxsl:node-set($ListPopulatedWithMain)/b:Citation/b:FirstAuthor">
<!-- hier wird die Klammer [ angezeigt -->
<xsl:call-template name="templ_prop_ISO690_GeneralOpen"/>
</xsl:if>
<xsl:if test="msxsl:node-set($ListPopulatedWithMain)/b:Citation/b:PagePrefix">
<xsl:value-of select="/b:Citation/b:PagePrefix"/>
</xsl:if>
<!-- <xsl:value-of select="$displayAuthor" /> nicht den Author anzeigen sondern den Tag-->
<xsl:value-of select="msxsl:node-set($ListPopulatedWithMain)/b:Citation/b:Source/b:Tag" />
<xsl:if test="string-length($displayTitle) > 0">
<xsl:if test="string-length($displayAuthor) > 0">
<xsl:call-template name="templ_prop_ListSeparator"/>
</xsl:if>
<xsl:value-of select="$displayTitle"/>
</xsl:if>
<xsl:if test="string-length($year) > 0">
<xsl:if test="string-length($displayTitle) > 0">
<xsl:call-template name="templ_prop_ListSeparator"/>
</xsl:if>
<!-- <xsl:value-of select="$year"/> nicht das Jahr anzeigen lassen -->
</xsl:if>
<xsl:if test="string-length($author0) = 0 and string-length($title0) = 0 and string-length($year0) = 0">
<xsl:value-of select="msxsl:node-set($ListPopulatedWithMain)/b:Citation/b:Source/b:Tag"/>
</xsl:if>
<xsl:if test="string-length($volume) > 0 or string-length($pages) > 0">
<xsl:if test="string-length($displayAuthor) > 0 or string-length($displayTitle) > 0 or string-length($year) > 0">
<xsl:call-template name="templ_prop_Space"/>
</xsl:if>
<xsl:choose>
<xsl:when test="string-length($volume) > 0 and string-length($pages) > 0">
<xsl:value-of select="$volume"/>
<xsl:call-template name="templ_prop_Enum"/>
<xsl:value-of select="$pages"/>
</xsl:when>
<xsl:when test="string-length($volVolume) > 0">
<xsl:value-of select="$volVolume"/>
</xsl:when>
<xsl:when test="string-length($ppPages) > 0">
<xsl:value-of select="$ppPages"/>
</xsl:when>
</xsl:choose>
</xsl:if>
<xsl:if test="/b:Citation/b:PageSuffix">
<xsl:value-of select="/b:Citation/b:PageSuffix"/>
</xsl:if>
<xsl:if test="/b:Citation/b:LastAuthor">
<!-- hier wird die Klammer ] angezeigt -->
<xsl:call-template name="templ_prop_ISO690_GeneralClose"/>
</xsl:if>
<xsl:if test="not(/b:Citation/b:LastAuthor)">
<xsl:call-template name="templ_prop_GroupSeparator"/>
</xsl:if>
I have tried to add - in this part but it just shows the hyphen at the beginning or at the end. Changing the letters into uppercase is still magic for me. could not find the relevant section.
For the 2nd part I will upload the file since it is pretty long and i don't want to post the entire code. Can't do it from work since every possibility for an upload is blocked by my company.
At first I would recommend you to use templates e.g:
<xsl:template name="Citation">
<xsl:apply-templates/>
</xsl:template>
<xsl:template name="FirstAuthor">
<xsl:call-template name="templ_prop_ISO690_GeneralOpen"/>
</xsl:template>
<xsl:template name="PagePrefix">
<xsl:value-of select="."/>
</xsl:template>
...
This is not necessary, but better code style.
Your code is unreadable for me so I will answer your question like that:
- For transforming the text to upper-case use
<xsl:value-of select="upper-case(//some-xpath)"/>
To insert tables use code like this:
Text
Text
If you expect a better answer please post some readable code

change the class of a link with xslt

I would like to change the class of a link but something must be wrong, however I can't see where.
I have checked that the if test is OK.
Could you tell me where I was wrong ?
<xsl:template match="*" mode="title-link-proced">
<a target="BodyPart" class="little_link">
<xsl:if test="#change = 'true'">
<xsl:attribute name="class">little_link_evolution</xsl:attribute>
</xsl:if>
</a>
</xsl>
I also tried
<xsl:template match="*" mode="title-link-proced">
<a target="BodyPart" class="little_link">
<xsl:if test="#change = 'true'">
<xsl:attribute name="class" select="little_link_evolution"></xsl:attribute>
</xsl:if>
</a>
</xsl>
but that dit not work either
EDIT:
I checked that there is a change attribute with the value true (if I display:
<xsl:value-of select="#change"/>
I get true)
EDIT 2
XML iput
<level_4 change="true" module="2X3E-ZE_RTY_OAD" title="presentation">
</level_4>
OK, it might help some one day
rather than attemting to modify the existing class, I decide not to attribute a class in the beginning and to do this:
<a target="BodyPart">
<xsl:choose>
<xsl:when test="#change = 'true'">
<xsl:attribute name="class">little_link_evolution</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="class">little_link</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
And it worked !

XSLT setting a variable to either foo or #foo depending on presence of attribute

I'm trying to set parttext to #head if use_head="true" is not present and to the contents of <head> </head> if use_head="true" is present
<xsl:template match="toc_part">
<xsl:variable name="artnum">
<xsl:value-of select="../#num" />
</xsl:variable>
<xsl:variable name="partnum">
<xsl:value-of select="#num" />
</xsl:variable>
<xsl:variable name="parttext">
<xsl:if test="#use_head">
<xsl:value-of select="head"/>
</xsl:if>
<xsl:if test="not[#use_head]">
<xsl:value-of select="#head"/>
</xsl:if>
</xsl:variable>
<tr>
<td>
 
</td>
<td>
<a class="int" href="{$GBLfilePre}{$artnum}.html#{$artnum}{$partnum}"><xsl:text>Part </xsl:text><xsl:value-of select="$partnum" /></a>
</td>
<td>
<xsl:value-of select="$parttext" />
</td>
</tr>
</xsl:template>
I've also tried:
<xsl:if test="#use_head"><xsl:variable name="parttext"><xsl:value-of select="head"></xsl:variable>
<xsl:if test="not[#use_head"]><xsl:variable name="parttext"><xsl:value-of select="#head"></xsl:variable>
which give parttext undefined when referenced.
Try:
<xsl:variable name="parttext">
<xsl:choose>
<xsl:when test="#use_head='true'">
<xsl:value-of select="head"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="#head"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Your current test in the first if statement will evaluate to true() if the #use_head attribute exists, regardless of it's value. If you want the test to evaluate whether or not it's value is equal to "true" you should use test="#use_head='true'".
The second if statement is evaluating whether or not there is an element named "not" that has an attribute called "use_head", because the square brackets are a predicate. I believe you had intended to use the not() function: not(#use_head='true')
You could then use an <xsl:choose> instead of two if blocks:
<xsl:variable name="parttext">
<xsl:choose>
<xsl:when test="#use_head='true'">
<xsl:value-of select="head"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="#head"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
In XSLT 2.0:
<xsl:variable name="head"
select="if (#use_head='true') then head else #head"/>
In XSLT 1.0, either Hansen's solution, or
<xsl:variable name="head"
select="head[current()/#use_head='true'] |
#head[not(current()/#use_head='true')]"/>
In future, please tell us which version of XSLT you are using. One can sort of guess this must be XSLT 1.0 because in 2.0 the solution is trivial, but it's better not to have to guess.

Using Multiple Nested Attributes in XSLT

What is the best way to construct nested attributes in XSL?
My issue is that onmouseover is an attribute and the src of img is an attribute. The current error given by the builder is:
An item of type 'Element' cannot be constructed within a node of type 'Attribute'.
I used to have an issue of multiple attributes which would have been my preferred route but throws an error:
Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added.
I have since attempted the following as a workaround but with no luck
<xsl:template name="Item3">
<xsl:param name="ItemID" />
<xsl:variable name="IMGSRC">
<xsl:choose>
<xsl:when test="$ItemID = 'ST-18/NM/NM/36'">
<xsl:value-of select="concat('imagesCategories/','ST-18-NM-NM-36','.jpg')"/>
</xsl:when>
<xsl:when test="$ItemID = 'ST-18/NM/NM/48'">
<xsl:value-of select="concat('imagesCategories/','ST-18-NM-NM-48','.jpg')"/>
</xsl:when>
<xsl:when test="$ItemID = 'ST-18/NM/NM/72'">
<xsl:value-of select="concat('imagesCategories/','ST-18-NM-NM-72','.jpg')"/>
</xsl:when>
<xsl:when test="$ItemID = 'ST-18/SMAM/SMAM/12'">
<xsl:value-of select="concat('imagesCategories/','ST18-SMAM-SMAM-12','.jpg')"/>
</xsl:when>
<xsl:when test="$ItemID = 'ST-18/SMAM/SMAM/24'">
<xsl:value-of select="concat('imagesCategories/','ST18-SMAM-SMAM-24','.jpg')"/>
</xsl:when>
<xsl:when test="$ItemID = 'ST-18/SMAM/SMAM/36'">
<xsl:value-of select="concat('imagesCategories/','ST18-SMAM-SMAM-36','.jpg')"/>
</xsl:when>
<xsl:when test="$ItemID = 'ST-18/SMAM/SMAM/48'">
<xsl:value-of select="concat('imagesCategories/','ST18-SMAM-SMAM-48','.jpg')"/>
</xsl:when>
<xsl:when test="$ItemID = 'ST-18/SMAM/SMAM/60'">
<xsl:value-of select="concat('imagesCategories/','ST18-SMAM-SMAM-60','.jpg')"/>
</xsl:when>
<xsl:when test="$ItemID = 'ST-18/SMAM/SMAM/72'">
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('imagesCategories/',$ItemID,'.jpg')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="Items/Item[#ItemID=$ItemID]">
<xsl:attribute name="onmouseover">
<xsl:text>ddrivetip('</xsl:text>
<img src="{$IMGSRC}"/>
<br />
<b>
<xsl:value-of select="Items/Item[#ItemID=$ItemID]/#ItemID" />
</b>
<br />
<b>
<xsl:value-of select="Items/Item[#ItemID=$ItemID]/#ItemDescription" />
</b>
<br />
<br />
<xsl:text>Price (01-09): </xsl:text>
<xsl:value-of select="Items/Item[#ItemID=$ItemID]/#PriceLevel1" />
<br/>
<xsl:text>Price (10-24): </xsl:text>
<xsl:value-of select="Items/Item[#ItemID=$ItemID]/#PriceLevel2" />
<br/>
<xsl:text>Price (25-49): </xsl:text>
<xsl:value-of select="Items/Item[#ItemID=$ItemID]/#PriceLevel3" />
<br/>
<xsl:text>Qty In Stock: </xsl:text>
<xsl:value-of select="Items/Item[#ItemID=$ItemID]/#QtyOnHand" />
<br />
<br />
<xsl:text>Click </xsl:text>
<b>
<xsl:text>"BUY!"</xsl:text>
</b>
<xsl:text> to add this item to your shopping cart</xsl:text>
<xsl:text>', '', '300')</xsl:text>
</xsl:attribute>
There is some additional code and then the proper closing tags.
Thanks everyone!
It looks like you are trying to pass html as a string to your ddrivetip function. However, you are adding these as nodes instead of text, and nodes cannot be added added to attributes, so one solution is to make the nodes text (You'll have to escape the brackets and double quotes too).
However, you are putting a lot of information into the onmouseover event, which is not recommended. Instead of what you are currently doing, I would make a hidden element with an id that incorporates your itemId with the contents of your html and then show that as needed in your onmouseover event.
Use CDATA sections so that the XSLT Processor interpret your img tags as a part of text nodes and not as an attempt to insert element nodes into an attribute (it is forbidden by the XML specification)
<xsl:attribute name="onmouseover">
<xsl:text><![CDATA[ddrivetip('<img src="]]></xsl:text>
<xsl:value-of select="$IMGSRC" />
<xsl:text><![CDATA["/>
<br />
...