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.
Related
I just "inherited" this repository in my office. I have no experience at all with it and I've been asked to show custom metadata below an item's title in the summary view. The custom metadata has already been registered (it is called dc.magazine.title) and I managed to edit the input forms so that all the new metadata can be registered in the database.
The repository is using the default mirage theme with XMLUI. I have changed some code in the file DIM-Handler.xsl trying to emulate how the other info is rendered but I have no idea how it works so my approach has given no results. This is what I tried:
<!-- Magazine row -->
<tr class="ds-table-row {$phase}">
<td><span class="bold"><i18n:text>xmlui.dri2xhtml.METS-1.0.item-title</i18n:text>: </span></td>
<td>
<xsl:choose>
<xsl:when test="count(dim:field[#element='magazine'][#qualifier='title']) = 1">
<xsl:value-of select="dim:field[#element='magazine'][#qualifier='title'][1]/node()"/>
</xsl:when>
<xsl:otherwise>
<i18n:text>xmlui.dri2xhtml.METS-1.0.no-title</i18n:text>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
<xsl:call-template name="itemSummaryView-DIM-fields">
<xsl:with-param name="clause" select="($clause + 1)"/>
<xsl:with-param name="phase" select="$otherPhase"/>
</xsl:call-template>
But nothing is showing besides the default metadata. Can somebody give me a hand on how to show this new metadata? Some clues on how this code works so I can make future changes will be really appreciated!
If you are using the default installation of DSpace using the Mirage 1 theme, the display of the item's metadata is rendered in [DSpace-installed-directory]/webapps/xmlui/themes/Mirage/lib/xsl/aspect/artifactbrowser/item-view.xsl. In my comment, I specified [DSpace-installed-directory] since I'm not so sure if the repository you 'inherited' could be using a customized theme with a different theme name other than Mirage.
You said that you are required to show a custom metadata below the item's title. Try to insert this before the <!-- Author(s) row -->
<xsl:when test="$clause = 2 and (dim:field[#element='magazine' and #qualifier='title' and descendant::text()])">
<div class="simple-item-view-other">
<span class="bold"><i18n:text>xmlui.dri2xhtml.METS-1.0.item-title</i18n:text>:</span>
<span>
<xsl:for-each select="dim:field[#element='magazine' and #qualifier='title']">
<xsl:value-of select="./node()"/>
<xsl:if test="count(following-sibling::dim:field[#element='magazine' and #qualifier='title']) != 0">
<br/>
</xsl:if>
</xsl:for-each>
</span>
</div>
<xsl:call-template name="itemSummaryView-DIM-fields">
<xsl:with-param name="clause" select="($clause + 1)"/>
<xsl:with-param name="phase" select="$otherPhase"/>
</xsl:call-template>
</xsl:when>
Please take note of the $clause number. You should update all the clause number below ie the author's row should be $clause = 3 down to the part of
<!-- IMPORTANT: This test should be updated if clauses are added! -->
<xsl:if test="$clause < 8">
<xsl:call-template name="itemSummaryView-DIM-fields">
<xsl:with-param name="clause" select="($clause + 1)"/>
<xsl:with-param name="phase" select="$phase"/>
</xsl:call-template>
</xsl:if>
#euler Thank you for your answer, with your post, (though 4 years old), I was able to make out how this simple item view works and created an entry with dc.identifier.citation. as follows
<xsl:when test="$clause = 6 and (dim:field[#element='identifier' and #qualifier='citation'])">
<div class="simple-item-view-other">
<span class="bold"><i18n:text>xmlui.ETCRiverRun.METS-1.0.item-citation</i18n:text>:</span>
<span>
<xsl:for-each select="dim:field[#element='identifier' and #qualifier='citation']">
<xsl:copy-of select="./node()"/>
<xsl:if test="count(following-sibling::dim:field[#element='identifier' and #qualifier='citation']) != 0">
<br/>
</xsl:if>````
I would like to set an xsl variable based on a condition. The xsl below is not currently working for me. I've been able to make two different matchers (<xsl:template match="rule/condition" and <xsl:template match="condition/condition") which enables me to put the ;display:none on just condition/condition matches but that results in the template being duplicated except for the one part of ;display:none. Guess I'm under the impression that I should be able to dynamically set a variable based on a condition but maybe my impression is wrong?
<xsl:template match="condition">
<xsl:variable name="display">
<xsl:if test='name(..)=condition'>;display=none</xsl:if>
</xsl:variable>
<div style="{$divIndent}{$display}">
<a href="javascript:void(0)" style="{$expandPosition}" onclick="expandContents(this)">
<span class="glyphicon glyphicon-plus"></span>
</a>
<condition type="<xsl:value-of select="#type"/>"><br />
<xsl:apply-templates select="expression" />
<xsl:apply-templates select="condition" />
</condition>
</div>
</xsl:template>
<xsl:if test='name(..)=condition'>;display=none</xsl:if>
This asks if the name of the parent is equal to the value of the child whose name is condition. You probably want to know if the name of the parent is the literal value "condition":
<xsl:if test='name(..)="condition"'>;display=none</xsl:if>
However, it might be more idiomatic to write:
<xsl:if test='parent::condition'>;display=none</xsl:if>
Note also that display:none is valid css, display=none prbably won't work.
Try below code by adding attribute style
<div><xsl:attribute name ="style"><xsl:if test='name(..)=condition'>display=none;</xsl:if></xsl:attribute></div>
I have a front page where i need to display a selected news item from the news section of the site, including an image.
I started off by trying to do a simple modification of the standard image, and promptly got nowhere.
I have verified that the images work when shown via currentpage directly on the node, but the following does not work:
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="mediaID" select="$currentPage/forsidenyhed/billede" />
<xsl:value-of select="$currentPage/forsidenyhed" />
<xsl:if test="string($mediaID) != ''">
<xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/forsidenyhed/billede, false)" />
<xsl:if test="string($media) != ''">
<div class="forsidebillede">
<img src="{$media/umbracoFile}" alt="{$media/altText}" />
</div>
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
The value-of outputs the correct node-id for the node containing the image i am looking for.
Edit: For anybody having problems with the same exact situation (umbraco cms) i recomend using a Razor macro instead of XSLT.
Following code provides the functionality i was looking for:
#inherits umbraco.MacroEngines.DynamicNodeContext
#using umbraco.MacroEngines
#{
dynamic settingsNode = Model.AncestorOrSelf();
dynamic searchPageNode = new DynamicNode(settingsNode.forsidenyhed);
dynamic mediaItem = new DynamicMedia(#searchPageNode.billede);
}
<img src="#mediaItem.umbracoFile">
In the last node of my site is where the articles are shown, and everyone has its own tags that of course can be the same between some of them, so I wrote a Macro for tags that is working (it lists the tags of the article the user is viewing), I've used the Tag datatype for my 'Article' doctype, and that Macro works correctly; but I got problems with the Macro I wrote to list those articles that have the same tags, I called it RelatedContent.xslt. Here is the code for AllTags.xslt that I found in Umbraco TV Tutorials that works:
<xsl:template match="/">
<div class="tags">
<xsl:variable name="Factor" select="6 div Exslt.ExsltMath:max(tags:getAllTagsInGroup('default')/tags/tag/#nodesTagged)"/>
<xsl:for-each select="tags:getAllTagsInGroup('default')/tags/tag">
<a class="tag{round($Factor * #nodesTagged)}x" href="?tag={.}">
<xsl:value-of select="."/>
</a><br/>
</xsl:for-each>
</div>
</xsl:template>
And the code for RelatedContent.xslt is this:
<xsl:template match="/">
<ul>
<xsl:for-each select="$currentPage/node [string(data [#alias='umbracoNaviHide']) != '1'] and (umbraco.library:Request('tag') = '' or contains(data [#alias = 'tags'], umbraco.library:Request('tag')))">
<li>
<a href="{umbraco.library:NiceUrl(#id)}">
<xsl:value-of select="#nodeName"/>
<xsl:value-of select="newsTitle"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:template>
I have not found anything to help me understand this, so I cannot realize how to do it. I will appreciate some help from you. Thanks for your advices.
(Umbraco 6.1.3)
The code for the related content is using the old XML Schema.
Replace this bit:
<xsl:for-each select="$currentPage/node [string(data [#alias='umbracoNaviHide']) != '1']
and (umbraco.library:Request('tag') = '' or contains(data [#alias = 'tags'],
umbraco.library:Request('tag')))">
</xsl:for-each>
With
<xsl:variable name="tag" select="umbraco.library:Request('tag')"/>
<xsl:for-each select="$currentPage/*[#isDoc][umbracoNaviHide != 1][contains($tag,./tag)]">
</xsl:for-each>
The /node element does not exist in the 4.6+ schema, and the element name is replaced with the name of the documentTypeAlias.
So if you have a document type article with a property articleTitle it would be like this:
$currentPage/article/
$currentPage/article/articleTitle
Instead of the old schema (this is incorrect for anything above 4.5)
$currentPage/node[#nodeTypeAlias = 'article']
$currentPage/node[./data[#alias] = 'articleTitle']
You can see the difference between the 2 schemas at the Umbraco wiki:
http://our.umbraco.org/wiki/reference/xslt/45-xml-schema
I am trying to create hyperlinks using XML information and XSLT templates. Here is the XML source.
<smartText>
Among individual stocks, the top percentage gainers in the S. and P. 500 are
<smartTextLink smartTextRic="http://investing.domain.com/research/stocks/snapshot
/snapshot.asp?ric=HBAN.O">Huntington Bancshares Inc</smartTextLink>
and
<smartTextLink smartTextRic="http://investing.domain.com/research/stocks/snapshot
/snapshot.asp?ric=EK">Eastman Kodak Co</smartTextLink>
.
</smartText>
I want the output to look like this, with the company names being hyperlinks based on the "smartTextLink" tags in the Xml.
Among individual stocks, the top percentage gainers in the S.&P. 500 are Eastman Kodak Co and Huntington Bancshares Inc.
Here are the templates that I am using right now. I can get the text to display, but not the hyperlinks.
<xsl:template match="smartText">
<p class="smartText">
<xsl:apply-templates select="child::node()" />
</p>
</xsl:template>
<xsl:template match="smartTextLink">
<a>
<xsl:apply-templates select="child::node()" />
<xsl:attribute name="href">
<xsl:value-of select="#smartTextRic"/>
</xsl:attribute>
</a>
</xsl:template>
I have tried multiple variations to try to get the hyperlinks to work correctly. I am thinking that the template match="smartTextLink" is not being instantiated for some reason. Does anyone have any ideas on how I can make this work?
EDIT: After reviewing some of the answers, it is still not working in my overall application.
I am calling the smartText template from within my main template
using the following statement...
<xsl:value-of select="marketSummaryModuleData/smartText"/>
Could this also be a part of the problem?
Thank you
Shane
Either move the xsl:attribute before any children, or use an attribute value template.
<xsl:template match="smartTextLink">
<a href="{#smartTextRic}">
<xsl:apply-templates/>
</a>
</xsl:template>
From the creating attributes section of the XSLT 1 spec:
The following are all errors:
Adding an attribute to an element after children have been added to it; implementations may either signal the error or ignore the attribute.
Try this - worked for me:
<xsl:template match="smartText">
<p class="smartText">
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="smartTextLink">
<a>
<xsl:attribute name="href">
<xsl:value-of select="#smartTextRic"/>
</xsl:attribute>
<xsl:value-of select="text()"/>
</a>
</xsl:template>
Trick is - <xsl:attribute> first, before you do any other processing.
Marc