Get XSLT global variable as test for Chrome - google-chrome

I'm new to the world of XSLT, I only know the basics. I am trying to modify some files to work on Chrome (at the moment they work only on IE). One if the issues I have now is in this section:
<td class="2k3ButtonContainer">
<div id="coolTheme" style="height:20px;direction:rtl;background:URL('../../Assets/UI/Images/{$name}.gif') no-repeat 100% 0px;padding-right:20px;" dir="rtl" class="2k3Button" onclick="{$onclick}">
<xsl:value-of select="$caption"/>
<xsl:if test="$hasDown='1'">
<img src="../../Assets/UI/Images/Splash/arrow.down.gif" align="absmiddle" style="width:7px;height:4px;margin:0 2 0 2"/>
</xsl:if>
</div>
</td>
The line <xsl:value-of select="$caption"/> that should replace the text of the div isn't working for Chrome. The variable exists, I know it because $name and $onclick are correct, but when placed in the div as text I cannot get the value of the caption variable. (I get the buttons with the correct images and events, but without labels).
I tried to read about it, but I am not sure what to look for, and I didn't understand the little info I found about it.
Thanks all in advance.

XSLT variable references are tricky. Try referencing it the long way instead:
<xsl:value-of select="document('')/*/xsl:variable/#select[../#name='caption']"/>

Related

XSLT Transformation of Hyperlinks

I have an XSLT web page that transforms a table I have extracted from MS Access. In the xml document I have some hyperlinks such as C:\My Work\My HTML test.htm and as far as I know the white space is preserved. My problem is that when I transform this to a Hyperlink the link changes to file:///C:\My%20Work\My%20HTML%20test.htm which does not work. I have other links that are formed in the normal way (without spaces) that work fine so I can pinpoint the issue to the addition of the %20.
I have the command:
<xsl:preserve-space elements="clmAttach1Link clmAttach2Link"/>
in the XSL document. The code to transform the XML is:
<a>
<xsl:attribute name="href">
<xsl:value-of select="clmAttach1Link"/>
</xsl:attribute>
<xsl:value-of select="clmAttach2Name"/>
</a>
This code displays all of the information correctly just does not link to the local files.
Can anyone help me transform the hyperlinks to retain the spaces so I can link to local files?
Thanks
What is the correct link suppose to be? Should it be with spaces? else you could try to use:
<xsl:strip-space>
And have a path without spaces.
Spaces in URLs is not considered safe, but you can try using <xsl:text>:
<xsl:text disable-output-escaping="yes"><a href="</xsl:text>
<xsl:value-of disable-output-escaping="yes" select="clmAttach1Link"/>
<xsl:text disable-output-escaping="yes">"></xsl:text>
<xsl:value-of disable-output-escaping="yes" select="clmAttach2Name"/>
<xsl:text disable-output-escaping="yes"></a></xsl:text>
or only value-of and concat:
<xsl:value-of disable-output-escaping="yes" select="concat(
'<a href="', clmAttach1Link, '">', clmAttach2Name ,'</a>')"/>

XSLT is adding additional characters to HTML image elements

So I am creating a webpage from an XML file that I created. It is a list of all cards and their attributes from Hearthstone.
When it comes to images can someone explain why my xsl transformation is adding character data to the begging and end of my img content output? It does this even when I use a local image. I am using jEdit.
XML:
<Image_URL>
<regular>
http://hydra-media.cursecdn.com/hearthstone.gamepedia.com/thumb/3/37/Abomination%28597%29.png/184px-Abomination%28597%29.png?version=9e47af5b792479ac6617cb30bf7da8a4
</regular>
<gold>
http://hydra-media.cursecdn.com/hearthstone.gamepedia.com/thumb/1/10/Abomination%28597%29_Gold.png/184px-Abomination%28597%29_Gold.png?version=a340c375a36e6c10eec4a747a3170901
</gold>
</Image_URL>
XSL:
<xsl:template match="regular">
<p>
<img src="{.}"/>
</p>
</xsl:template>
Output:
<img src="%0A%09%09%09http://hydra-media.cursecdn.com/hearthstone.gamepedia.com/thumb/3/37/Abomination%28597%29.png/184px-Abomination%28597%29.png?version=9e47af5b792479ac6617cb30bf7da8a4%0A%09%09%09"></p>
You are seeing the additional whitespace surrounding the URL data, given that the element is pretty-printed.
Use normalize-space in the attribute value template to remove this:
<xsl:template match="regular">
<p>
<img src="{normalize-space(.)}"/>
</p>
</xsl:template>

Sitecore Link (Xslt) Question Mark Issue

I got some code in XSLT in my sitecore project which displays link:
<sc:link title="{sc:fld('MenuTooltip',.)}">
<xsl:call-template name="DisplayTitle"/>
</sc:link>
This is working fine unless I got text with '?' on MenuTooltip Field in sitecore.
For example, if MenuTooltip got "Reference Centre" it's fine it generates below html
<a title="Reference Centre" href="/reference-centre">Reference Centre</a>
Perfect now the things get bad, If I got "Reference Centre?" in MenuToolTip it generates some thing like below
<a &haschildren="true" href="/reference-centre">Reference CentreReference Centre</a>
Any ideas on this?
There might be two issues either you have some custom code running on sc:Link. check the below configaration in web.config
in my case i have not had any custom code and i am using Sitecore.NET 6.6.0 (rev. 130529).
So
I replaced sc:link with anchor tag:
<a href="{sc:path(.)}" title="{sc:fld('MenuTooltip',.)}">
<xsl:call-template name="DisplayTitle"/>
</a>
Suggested by -John west

How to add an ID attribut to xml elements using xslt transformation

I am very new to xml and xslt transformation. I need some advice.
Basically I have managed to display a range of images from my XML page using XLTR Transformation.
The original xml has no ID's associated with each image, I cant alter the xml. Therefore I was wondering if there was a way in xslt to add an ID attribute to each image before it is outputted to the browser? As I want to be able to control each element/image individually using CSS.
I hope that makes sense?
The xslt is as follows.
<xsl:for-each select=" cars/car_type">
<!-- <h5> <xsl:value-of select="car-type"/> </h5> -->
<div class ="images">
<img>
<xsl:attribute name="src">
<xsl:value-of select="image"/>
</xsl:attribute>
</img>
</div>
</xsl:for-each>
Thanks again.
You can use generate-id (http://www.w3.org/TR/xslt#function-generate-id) function to generate an id for an input node e.g.
<xsl:for-each select="cars/car_type">
<div class="images">
<img src="{image}" id="{generate-id(image)}"/>
</div>
</xsl:for-each>
When you create the CSS elsewhere in your stylesheet you simply need to make sure you process the image elements again and use generate-id again.

XSLT document for-each and image syntax

I am trying to use the code below to select all values of notableWork, so for each notableWork get its value and get the next one etc. It is sort of working as two "Notable Work:" are appearing just not the values of notable work.
<xsl:for-each select="notableWork">
<p>
Notable Work: <xsl:value-of select="notableWork" />
</p>
</xsl:for-each>
The other issue I am having is with images. I have been messing around with the img tag trying variations of it, below is just what I have ended up with. I have an element called imaged which contains a value of image2.jpg, image4.jpg etc. I cannot seem to get it to work :P Just wondering what the correct syntax is, using google I found variations of so really not sure.
<img src="<xsl:value-of select="image" />" />
Thanks :)
<xsl:for-each select="notableWork">
<p>
Notable Work: <xsl:value-of select="notableWork" />
</p>
</xsl:for-each>
can never work unless you have a nesting like notableWork/notableWork. You already selected notableWork so you cant select it again. So you should work with the node, the current node. Which is XSLT: ., current() or XPath: self::node(). All 3 can be used for the same effect.
Notable Work: <xsl:value-of select="." />
or
Notable Work: <xsl:value-of select="current()"/>
To set the attribute of a image tag you can use
<img>
<xsl:attribute name="src">
<xsl:value-of select="images" />
</xsl:attribute>
</img>
or
<img src="{image}"/>