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>
Related
I have a problem writing my XSL. I have a link with the following code:
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($myUrl,'&projectNumber=',$projectNumber)"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="title"/>
</xsl:attribute>
LINK
</a>
So I need to pass a variable projectNumber to the end of myUrl. This works just fine and I get ...myUrl...&projectNumber=...projectNumber... in HTML.
The problem is, that the variable projectNumber sometimes has some characters which have to be escaped in the href of my link. I tried using the XSL function str:escape-uri() in many different ways, but still no success...
For example if myUrl is www.example.com/example.aspx?a=b and projectNumber is aaaūaaa
I get href like www.example.com/example.aspx?a=b&projectNumber=aaaūaaa, but I need to get www.example.com/example.aspx?a=b&projectNumber=aaa%C5%ABaaa. (%C5%AB is the way that 'ū' is escaped) Any suggestions? Thanks.
If you are using XSLT 1.0,
then refer this.
In case of XSLT 2.0, you may use this to solve the issue.
<xsl:value-of select="concat($myUrl,'&projectNumber=',encode-for-uri($projectNumber))"/>
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.
xslt is pretty new for me. Is it possible to do something similar to my code below. I know it is possible in other template languages.
<div class="<xsl:if test="position()=1">myclass</xsl:if>">Hello</div>
You could wrap an xsl:attribute in an xsl:if...
<div>
<xsl:if test="position()=1">
<xsl:attribute name="class">myclass</xsl:attribute>
</xsl:if>
<xsl:text>Hello</xsl:text>
</div>
Also, in XSLT 2.0, you can write the xsl:attribute like this:
<xsl:attribute name="class" select="'myClass'"/>
Another XSLT 2.0 option, if you don't mind having an empty class="", is to use an if in an AVT (Attribute Value Template):
<div class="{if (position()=1) then . else ''}">...</div>
The then may vary depending on context.
It should be something like this:
<xsl:variable name="myclass" select="variablenode" />
<div class="adf">
<xsl:if test="yournode[position()=1]">
<xsl:value-of select="$myclass"/>
</xsl:if>
Hello</div>
But please give us your source XML, the XSLT you have so far and the expected output. Otherwise we can only guess.
I have in an input file:
<a></a>
<b/>
<c>text</c>
I need to converting this to string. Using transformer I am getting below output:
<a/> <!-- Empty tags should not collapse-->
<b/>
<c>text</c>
If I use xslt and output method is "HTML", I get the below output:
<a></a> <!-- This is as expected-->
<b></b> <!-- This is not expected-->
<c>text</c>
I want the structure same as in input file. It is required in my application since I need to calculate index and it will be very difficult to change the index calution logic.
What would be the correct XSLT to use?
What XSLT processor? XSLT is merely a language to transform xml so "html output" is dependent on the processor.
I'm going to guess this first solution is too simple for you but i've had to use this to avoid processing raw html
<xsl:copy-of select="child::node()" />
as this should clone the raw input.
In my case, I have used the following to extract all nodes that had the raw attribute:
<xsl:for-each select="xmlData//node()[#raw]">
<xsl:copy-of select="child::node()" />
</xsl:for-each>
Other options:
2) Add an attribute to each empty node depending on what you want it to do later ie role="long", role="short-hand".
3)
Loop through each node (xsl:for-each)
<xsl:choose>
<xsl:when test="string-length(.)=0"> <!-- There is no child-->
<xsl:copy-of select="node()" />
</xsl:when>
<xsl:otherwise>
...whatever normal processing you have
</xsl:otherwise>
4) Redefine your problem. Both are valid XHTML/XML, so perhaps your problem can be reframed or fixed elsewhere.
Either way, you may want to add more information in your question so that we can reproduce your problem and test it locally.
P.S. Too much text/code to put in a comment, but that's where this would belong.
A possible alternative is to use disable-output-escaping like this:
<xsl:text disable-output-escaping="yes"><a></a></xsl:text>
But I understand that this is a dirty solution...
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>