Lets say I have the following code snippet below, how do I also apply the disable-output-escaping to the {name} in the title attribute?
<a title="{name}"><xsl:value-of select="name" disable-output-escaping="yes" /></a>
This has really got me stumped.
Thanks guys.
This cannot be done with XSLT. The spec says:
It is an error for output escaping to
be disabled for a text node that is
used for something other than a text
node in the result tree.
Thus it makes no difference if you use Attribute Value Templates or xsl:attribute with xsl:value-of, because you're generating an attribute node, not a text node. It's a limitation in the language.
You can't as is. The {name} shortcut doesn't allow additional parameters. Use the <xsl:attribute> tag instead.
Related
I have several html files starting with a title and the author name, but I don't want them in the table of content. I used remove toc from toc in wkhtmltopdf to hard code the value of the h1/h2 to remove but I would like the xlst toc file to be independent of the name of the document and the author.
So I gave these specific titles a class attribute. The problem lies in the xlst filter, I didn't find a way to test or extract the class attribute.
Here is a part of the html file :
<h1 class="title">Me</h1>
<h2 class="author">My Title</h2>
Here is the xslt toc file part :
<xsl:template match="outline:item">
<li>
<xsl:if test="(#title!='') and (#title!='My little TOC')and (#class!='author')and (#class!='title')">
I'm a total newbie to xslt and don't know what outline:item really is, but it seems that it doesn't get the original class attribute. How could I get the job done ?
One simple solution is to use div tags instead of headings. In your CSS, make sure you specify display: block;.
if you run the
--dump-outline toc.xml
flag when you generate the pdf and look at the xml file you will see the xml nodes and attributes.
You can then test for either the title, page number, link and backlink the document. You can use these attributes for your if statment.
For example:
<xsl:if test="((#page!=1) and (#page!=2) and (#page!=5))">
blah blah blah
</xsl:if>
Note the brackets around the full test.
You can even then nest the if statements further if needed:
<xsl:if test="((#page!=1) and (#page!=2) and (#page!=5))">
<xsl:if test="(#title!='A title')">
more code
</xsl:if>
</xsl:if>
I am creating an xsl file.
I want to print below code as output
<li class="td-nav-flyout {position:'containerleft'}">
But when I run the code java says "cannot compile stylesheet".
Please help.
Thanks in advance.
-Ritesh
What about the xsl:attribute element?
<li>
<xsl:attribute name="class">td-nav-flyout {position:'containerleft'}</xsl:attribute>
</li>
Use the following:
<li class="td-nav-flyout {{position:'containerleft'}}">
Normally, the curly braces inside attribute text allow you to evaluate XPath expressions. See Attribute Value Templates in the spec for full information.
I'm trying to write some XSLT which basically should go through the following algorithm:
if child of current node is of type Accordion
if child of Accordion node is of type AccordionItem
take the AccordionItem's title and content and display in <div> tags
end if
end if
It seems pretty straight forward, but the code I currently have doesn't appear to be working as it should. I must be missing something, but I can't figure out exactly what. Here's my XSLT code so far:
<xsl:for-each select="$currentPage/ancestor-or-self::Home//AccordionItem[#isDoc]">
<div id="accordion">
<h3><a href='#'><xsl:value-of select="accordionItemTitle"/></a></h3>
<div><xsl:value-of select="accordionItemContent" disable-output-escaping="yes" />
</div>
</div>
</xsl:for-each>
Can anyone offer any suggestions as to why this wouldn't be working correctly? Thanks in advanced!
It seems that your XPath isn't quite behaving as you've defined in your algorithm and is navigating to the node of type Home, is that intended?
If not, try modifying the XPath to the following:
<xsl:for-each select="$currentPage/Accordion/AccordionItem[#isDoc]">
I’m using Umbraco 4.7.0
My goal is to get the image path from a hard coded media node id of 4191. If I create a new macro with the code:
<xsl:copy-of select="umbraco.library:GetMedia(4191, false())"/>
I get the output:
/media/17675/my image.jpg50033618497jpg
I was expecting some well formed xml, however, it appears I’m missing all the tags. I therefore cannot reference the path for the image directly.
Am I missing something really simple here?
EDIT
I discovered how to get the raw xml output from my copy-of statement. I needed to wrap it in a <textarea> tag:
<textarea>
<xsl:copy-of select="umbraco.library:GetMedia(4191, false())"/>
</textarea>
This should do it:
<xsl:copy-of select="umbraco.library:GetMedia(4191, 0)/umbracoFile"/>
See also http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia
What is the best way to strip/replace the {} characters from the Sitecore item #id output in xslt?
Problem:
I have to identity certain tags in my html from the id attribute. Using names is dangerous because of the risk of the Sitecore end user typing spaces or illegal characters in the name.
On the other hand using the item id causes the id in the html to say: id="{xxxxxxxx-xxx(...)}, in which case the {} are illegal as characters in html id attribute.
So:
What is the best way to strip/replace the {} characters from the xslt #id output?
I am not familiar with Sitecore but with XSLT/XPath the expression translate(#id, '{}', '') should suffice to remove any curly braces from the id attribute value. Be careful however with any XSLT code using attribute value templates as there the curly braces have a special meaning. So <xsl:value-of select="translate(#id, '{}', '')"/> is safe as the select attribute is not treated as an attribute value template.
Right way to do this would be with NormalizeGuid.
I have used before (on Sitecore V5) NormalizeGuid Method from MainUtils.
I just tested on Sitecore 6.2 but it is breaking because there are 2 same method names. This results in an XslTransformException
Which version of Sitecore you are using? I suggest trying out NormalizeGuid:
Goes something like:
Web.Config
<extension mode="on" type="Sitecore.MainUtil, Sitecore.Kernel" namespace="http://www.sitecore.net/util" singleInstance="true"/>
XSLT
xmlns:util="http://www.sitecore.net/util"
and
<xsl:variable name="itmId"><xsl:value-of select="#id"/></xsl:variable>
<xsl:value-of select="util:NormalizeGuid($itmId)"/>
If you get RTE it is possible to fix it with a custom wrapper class. Take a look this post.
Actually, I think you can get around this by using GenerateShortID() it's also in MainUtil.
Thanks Martin, using the translate() function helped me out, but your answer is not complete.
The question - as I understand it - was concerning stripping curly braces inside angle braces in HTML, and here <xsl:value-of select="..."/> unfortunately wont work.
Consider this (illegal) code:
<div id="<xsl:value-of select="translate(#id, '{}', '')"/>">`
Instead, use this:
<div id="{translate(#id, '{}', '')}">
You can do it like this to include only the hyphens:
item.ID.Guid.ToString("D")
Alternatively you can use the following formats:
D: hyphens fed3f822-e79f-4318-a99d-aaf75feea459
N: digits fed3f822e79f4318a99daaf75feea459
B: braces {fed3f822-e79f-4318-a99d-aaf75feea459}
P: parenthese (fed3f822-e79f-4318-a99d-aaf75feea459)