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>
Related
Creating an ItemStyle XSL file for content query Webpart, i want to get value from the Pages library that inherits from Article Pages. this is OK with title or fields with no space. However, i seems not to work with field containing space, its display name is Article Date. I did try the following code:
<xsl:value-of select="#Article Date" />
Could you tell me, how could i do in such case? should i call external name of this field inside xsl file, like or other ways?
According to this page, the internal name for "Article Date" is ArticleStartDate. Try using that instead, and you may have more success.
<xsl:value-of select="#ArticleStartDate" />
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
My purpose is to get data from google place. I have the following snippet html:
<div class="rsw-pp rsw-pp-widget">
<div g:type="AverageStarRating"
g:secondaryurls="http://maps.google.com/?cid=12948004443906002997"
g:decorateusingsecondary="http://maps.google.com/?cid=12948004443906002997" g:groups="maps" g:rating_override="2.998000" class="rsw-stars">
</div>
</div>
I want to get value of g:rating_override. I tried with following xsl
<Rating>
<xsl:value-of
select="//div[#class='rsw-pp rsw-pp-widget']/div[#class='rsw-stars']/#g:rating_override" />
</Rating>
It said that 'System.Xml.Xsl.XsltException: Prefix 'g' is not defined'. Could you help me?
You need to define the "g" namespace. Typicaly this is done on the stylesheet element.
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:g=" ... "
version="1.0">
If you're using the Html Agility Pack embedded XSLT tools, you're facing two hard Html Agility Pack limits (at least with version 1.3.0.0):
Support for Namespaces is limited
The XPATH implementation does not support navigating to the attributes (only selection). This XPATH "//tag1/tag2/#myatt" does not work for example.
You can overcome these limits with C# code, but not easily with pure XPATH, hence not with XSLT.
In these case, it's often easier to convert the HTML to XML using the Html Agility Pack, and then use a regular XSLT on XML with the standard .NET classes, instead of XSLT on HTML with Html Agility Pack classes.
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.
How can print a page using xslt.
i need a link, or a button which when clicked invokes the print page printer dialog box.
I suspect you need to specify a bit more about what you are trying to do.
XSLT is simply a way to turn one block of text into another. The input is generally an xml buffer and the output is some text rendering of that buffer.
It is possible that you are trying to generate a script using XSLT and that you want that script to be able to open a print dialog when it is run by something e.g. you generate javascript, that then runs on a browser.
Can you describe in more detail what you want to achieve?
The following in an html page gives you a print link:
Print
XSLT is a language for transforming XML documents. That means you can add/modify content. Assuming your output is HTML, you can do this:
<xsl:template match="top">
<html>
<head>
</head>
<body>
<input name="print" type="button" value="Print"
onclick="javascript:window.print()">
<xsl:apply-templates />
</body>
</html>
</xsl:template>
But of course, where exactly the button has to go depends on your needs. I'd additionally, add a media=print specific CSS at the top so that the document comes out neat!