umbraco: get USER properties, NOT member properties in XSLT - 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>

Related

DITA Open Toolkit CHM (HTML Help Workshop) output

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

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.

Display images from tree list in Sitecore

In Sitecore, I have a tree list for the user to select certain images. I would like to use the presentation api to display the images that the user selects. While looking through the Presentation Component XSL reference guide, I found this code:
<xsl:variable name="slideShow" select="/*/item[#key='content']/item[#key='home']/item[#key='Foundation']/item[#key='Landing Pages']/item[#key='Legends Trail Ride']" />
<xsl:variable name="mediaid" select="sc:fld('Slide Show',$slideShow,'mediaid')" />
<xsl:if test="$mediaid">
<xsl:variable name="mediaitem" select="sc:item($mediaid,$slideShow)" />
<xsl:if test="$mediaitem">
<a href="{concat('/',sc:GetMediaUrl ($mediaitem))}">
<xsl:choose>
<xsl:when test="sc:fld ('title',$mediaitem)">
<sc:text field="title" select="$mediaitem" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$mediaitem/#name" />
</xsl:otherwise>
</xsl:choose>
</a>
</xsl:if>
</xsl:if>
The page will display so technically there isn't anything wrong with the code but the image still aren't showing. Is this code going in the right direction or is there an alternative way to display images from a tree list?
If your site is using the 'web' database, make sure you have published all of your media items or they won't display.
A typical scenario for your case would be to check if all templates and subtemplates of the specific items on which those images are attached are published. If this is done check your media library folders and media items in those folders. You have to make sure the folder in which you added the images is also published. What you can do to verify the above after you have published is login to the 'desktop' mode of Sitecore and change the database (bottom right corner) to 'web'. Then find all of the described items and see if everything is really published. Most of the times you will encounter issues like this it will actually be publishing.

Two microalias in single umbraco.library:RenderMacroContent method

For the desktop site I have a content in Umbraco where <p><?UMBRACO_MACRO macroAlias="StoryDesc" /></p> refers to XSLTName field
I am making a call from one XSLT to StroyDesc XSLT as
<xsl:variable name="StoryXSLT" select="$currentPage/XSLTName"/>
<xsl:value-of select="umbraco.library:RenderMacroContent(StoryXSLT, $currentPage/id)" />
Now for mobile site I have different XSLT MobileStoryDesc instead of StoryDesc. I cannot add a new separate content like <p><?UMBRACO_MACRO macroAlias="MobileStoryDesc" /></p>. But I can alter the existing content without affecting the present desktop site.
Is it possible to make a XSLT call. Please suggest me a solution. Thanks in advance.
I might not quite understand you, so apologies if I'm mixed up.
Why not create a MobileStoryXSLT & a DesktopStoryXSLT and use the StoryDescXSLT to choose which one to use?
Something like:
<xsl:if test="...desktop...">
<xsl:value-of select="umbraco.library:RenderMacroContent(DesktopStoryXSLT, $currentPage/id)" />
</xsl:if>
<xsl:if test="... mobile ...">
<xsl:value-of select="umbraco.library:RenderMacroContent(MobileStoryXSLT, $currentPage/id)" />
</xsl:if>

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>