XSL code cannot display image - xslt

I am using arcgis and I am trying to create an XSL template to configure my HTML PopUp to display attributes of a certain location. My problem is I cannot get the images to be displayed. I've tried using both codes below, but they don't work. The first one displays an empty frame while the second one displays <img src="E:\Pictures\Lakes\lake1.jpg">.
Can anyone help, please?
First version:
<xsl:when test="FieldName[starts-with(., 'Picture')]">
<img width="350" height="210">
<xsl:attribute name="src"><xsl:value-of select="FieldValue" disable-output-escaping="yes"/></xsl:attribute>
</img>
</xsl:when>
Second version:
<xsl:when test="FieldName[starts-with(., 'Picture')]">
<xsl:variable name="imageURL" select="FieldValue"/>
<p><img border="0" src="{$imageURL}" width="355" height="272"></img></p>
</xsl:when>

Related

Viewing an uploaded item in DSpace 4.2 xmlui

This is how the my search results page of DSpace looks like :
On clicking the item a new page opens up showing its description:
The description page opens the file upon clicking View/Open. Is it possible to directly open the file upon clicking its title on the results page? I want to skip the item description page.
As per my understanding this is the Java file which is called to render items. Do I need to make changes to this file? Or is it possible to achieve what I want by simply modifying the sitemap and xsl files?
The code that generates the thumbnail image is here.
https://github.com/DSpace/DSpace/blob/dspace-6_x/dspace-xmlui/src/main/webapp/themes/dri2xhtml/General-Handler.xsl#L34-L47
You could create similar logic to create an href to the original bitstream.
Look at the XML in /metadata/handle/xxx/yyy/mets.xml where xxx/yyy is your item handle. You should see the information that will point you to the original bitstream.
As was said in the comments, the xsl template to modify is the "itemSummaryList" in discovery.xsl
Replace that href value with $metsDoc//mets:FLocat[#LOCTYPE='URL']/#xlink:href"
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="$metsDoc//mets:FLocat[#LOCTYPE='URL']/#xlink:href"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="dri:list[#n=(concat($handle, ':dc.title')) and descendant::text()]">
<xsl:apply-templates select="dri:list[#n=(concat($handle, ':dc.title'))]/dri:item"/>
</xsl:when>
<xsl:otherwise>
<i18n:text>xmlui.dri2xhtml.METS-1.0.no-title</i18n:text>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
I was able to achieve what I wanted with help from Antoine Snyers, terrywb and this link. As pointed out by terrywb the information which I needed to read, i.e, the bitstream address of the uploaded file, was stored in the metsDoc. Here's a screenshot of my metsDoc with the fileSec expanded:
To be able to access the fileSec of the metsDoc I changed this line in discovery.xsl and this line in common.xsl to <xsl:text>?sections=dmdSec,fileSec&fileGrpTypes=ORIGINAL,THUMBNAIL</xsl:text>.
Then I added/modified the following code to the itemSummaryList in discovery.xsl so that the title hyperlink now points to the file bitstream.
<xsl:variable name="filetype">
<xsl:value-of select="$metsDoc/mets:METS/mets:fileSec/mets:fileGrp[#USE='CONTENT']"/>
</xsl:variable>
<xsl:variable name="fileurl">
<xsl:value-of select="$metsDoc/mets:METS/mets:fileSec/mets:fileGrp[#USE='CONTENT']/mets:file/mets:FLocat[#LOCTYPE='URL']/#xlink:href"/>
</xsl:variable>
<div class="artifact-title">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:choose>
<xsl:when test="$metsDoc/mets:METS/mets:dmdSec/mets:mdWrap/mets:xmlData/dim:dim/#withdrawn">
<xsl:value-of select="$metsDoc/mets:METS/#OBJEDIT"/>
</xsl:when>
<xsl:when test="$filetype">
<xsl:value-of select="$fileurl"/>
</xsl:when>
</xsl:choose>
</xsl:attribute>
Similarly, I also made changes to item-list.xsl file, and added this line <xsl:apply-templates select="mets:fileSec/mets:fileGrp[#USE='CONTENT']"
mode="itemSummaryList-DIM"/> to the template itemSummaryList-DIM.
So finally I got my desired result:
As visible in the inspector, the href attribute of the title now points to the original bitstream of the file :)

umbraco macro XSLT not working

I get an image folder parameter (folder present in the media section) from macro in Umbraco and then loop through the all the images. First thing I check that folder is not empty and then during the loop I further try to check if an image name is equal to "marhall_spadayhpbanner_jul131%20(4).jpg" then I need to put a different link to anchor. I have tried the following xslt code but for some reason its not working as expected and the second condition (when image equal to 'media/42595/marhall_spadayhpbanner_jul131%20(4).jpg' ) is never true.
Any ideas thanks
<xsl:for-each select="$imageFolderContents/node [#nodeTypeAlias='Image']">
<xsl:if test="string(current()/data [#alias='umbracoFile']) != ''">
<a href="www.somelink.com">
<img alt="{current()/#nodeName}">
<xsl:attribute name="src"><xsl:value-of select="current()/data [#alias='umbracoFile']"/></xsl:attribute>
</img>
</a>
</xsl:if>
<xsl:if test="string(current()/data [#alias='umbracoFile']) = 'media/42595/marhall_spadayhpbanner_jul131%20(4).jpg'">
<a href="someotherlink.com">
<img alt="{current()/#nodeName}">
<xsl:attribute name="src"><xsl:value-of select="current()/data [#alias='umbracoFile']"/></xsl:attribute>
</img>
</a>
</xsl:if>
</xsl:for-each>
The output is the code is
<div style="clear: both; position: relative; height: auto;" class="slideshow innerfade"><img alt="dont be a fool" src="/media/42595/marhall_spadayhpbanner_jul131 (4).jpg"><img alt="dont be a fool" src="/media/42595/marhall_spadayhpbanner_jul131 (4).jpg"><img alt="MH-Ext-16-hero.jpg" src="/media/1548/MH-Ext-16-hero.jpg"><img alt="golf_hero_arial_new.jpg" src="/media/1816/golf_hero_arial_new.jpg"><img alt="MH-Spa-e-25-hero.jpg" src="/media/1552/MH-Spa-e-25-hero.jpg"></div>
Replace the %20 in your if statement to a space. That should fix it.

How do I output html markup stored in a xsl:variable

I am trying to render markup stored in a variable but I am getting no joy. Reason its cached is because I am using this several times in the page
<xsl:variable name="imgHtml">
<figure>
<img src="{$img}" alt="" class="" />
<figcaption>
<p><xsl:value-of select="name" /></p>
Enlarge Image
</figcaption>
</figure>
</xsl:variable>
I then reference the variable using the value-of elment
<xsl:value-of select="$imgHtml" /> but for some reason, the HTML does not render. Don't be shy, I need the help. Thanks!
Use <xsl:copy-of select="$imgHtml"/>, value-of always creates a plain text node.
The other answers were not working for me, however this did:
<xsl:value-of select="$variable" disable-output-escaping="yes"/>

Using a link in XSL Files

I am completely new to XML so hopefully my explanations will make sense..
I am using an XSL file with 2 sections of HTML text, reading from 2 templates set up within the file.
The first text and associated template is a table, and I have set up a link within that. I want the link to then point to a picture that is part of the 2nd HTML text/template.
The link in the table is setup in that it appears as a link, underlined, etc. However it doesnt go anywhere when clicked.
The second section works fine on it's own, eg, pictures and text appears.
But what I cant figure out is how to actually get the link to work. I've tried numerous things but nothing has worked so far. And I-m not sure whether I am very close and just perhaps need to alter a line of code. Or whether I need to be doing something very different. Also, there are no error messages, and everything displays well, it's just the link itself that doesnt work.
<xsl:template match="portion">
<tr>
<td valign="top"><xsl:value-of select="food-description"/></td>
<td valign="top"><xsl:value-of select="food-number"/></td>
<!--the following is the link text-->
<td valign="top"><a><xsl:attribute name="href">#<xsl:value-of select="portion- photo/#file"/></xsl:attribute>
<xsl:value-of select="portion-photo/#file"/></a><br/>
</td>
</tr>
</xsl:template>
<xsl:template match="portion-photo">
<!--I know that this is the code that is not correct, however, believe it should be something similar-->
<a><xsl:attribute name="portion-photo"><xsl:value-of select="./#file"/></xsl:attribute></a>
<p><xsl:value-of select="../food-description"/>
<xsl:value-of select="./#file"/></p>
<img>
<xsl:attribute name="src"><xsl:value-of select="./#file"/></xsl:attribute>
<xsl:attribute name="width"><xsl:value-of select="ceiling(./#w div v2)"/></xsl:attribute>
<xsl:attribute name="height"><xsl:value-of select="ceiling(./#h div 2)"/></xsl:attribute>
</img>
</xsl:template>
Something like the following should work. Just add the missing name attribute to the anchor element:
<xsl:template match="portion">
...
<a href="#{portion-photo/#file}">
<xsl:value-of select="portion-photo/#file"/>
</a>
...
</xsl:template>
<xsl:template match="portion-photo">
<a name="{#file}">
<xsl:value-of select="#file"/>
</a>
</xsl:template>
However, you have to ensure that #file evaluates to a valid anchor name. If the values of all file attributes are unique, you could also create save IDs with generate-id():
<xsl:template match="portion">
...
<a href="#{generate-id(portion-photo)}">
<xsl:value-of select="portion-photo/#file"/>
</a>
...
</xsl:template>
<xsl:template match="portion-photo">
<a name="{generate-id()}">
<xsl:value-of select="#file"/>
</a>
</xsl:template>

Select check box from check box list xsl umbraco

I have a check box list with two check boxes. I want to output a link when either of them are checked. Both check boxes can be checked at the same time, or just one checked, or none at all.
I have a a variable named value where I am getting the dataType 2084 which is the check box list.
How can I target an individual check box within the list when it is checked. There preValues are 99 and 101.
Anyone who can help I am very much thankful!
Here is my attempt below.
<xsl:param name="currentPage"/>
<xsl:param name="parentNode" select="/macro/parentNode"/>
<xsl:template match="/">
<xsl:for-each select="$currentPage/OperationsMap[#id=$parentNode]/MarkerItem">
<xsl:variable name="value" select="umbraco.library:GetPreValues('2084')"/>
<div class="popup-box">
<xsl:if test="$value/preValue[#alias='99'] = '1'">
<div class="colorbox-link-container">
View current gallery
</div>
</xsl:if>
<xsl:if test="$value/preValue[#alias='101'] = '1'">
<div class="colorbox-link-container">
View historical project progress
</div>
</xsl:if>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
GetPreValues returns a data set for the umbraco raw data type, not the status if they're checked or not on any particular content node.
Assumptions (as not specified in question):
Your data type is going to look something like the following:
<preValues>
<preValue id="99">Red</preValue>
<preValue id="100">Green</preValue>
<preValue id="101">Blue</preValue>
</preValues>
Not knowing the property alias you gave the checkbox list when adding the data type to the document type, I'm just going to use the following
MarkerItem/colours
Code:
This code was written on the fly, so haven't had time to test it.
<xsl:for-each select="$currentPage/OperationsMap[#id=$parentNode]/MarkerItem">
<div class="popup-box">
<!-- get the colours checked on MarkerItem -->
<xsl:variable name="colours" select="./colours"/>
<xsl:variable name="coloursValues" select="umbraco.library:Split($colours, ',')" />
<!-- cycle through each of the checked colours -->
<xsl:for-each select="$coloursValues/value">
<xsl:choose>
<xsl:when test=". = 'Red'">
<div class="colorbox-link-container">
View current gallery
</div>
</xsl:when>
<xsl:when test=". = 'Blue'">
<div class="colorbox-link-container">
View historical project progress
</div>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</div>
Hopefully, that does the trick for you. Obviously, update any reference to colours and their value to what is specific to you.