I', trying to display the Body property of an Announcements List in my CQWP, but it is always blank.
In CommonViewFields I've tried to set Body type to Text, RichHTML, Note... all with no result. Also, as suggested elsewhere. I've tried disable-output-escaping="yes" in the xsl. Nothing changed.
Printing out the passed key / values reveals that Body is empty. It should be not.
<xsl:for-each select="#*">
Key:<xsl:value-of select="name()" />
Value:<xsl:value-of select="."/>
</xsl:for-each>
Any help?
Generally when you need to output HTML that exists in your data source (or any kind of "result tree"), try invoking the xsl:copy-of element.
To use your example, it would look like:
<xsl:for-each select="#*">
Key:<xsl:value-of select="name()" />
Value:<xsl:copy-of select="." />
<xsl:for-each select="#*">
Related
I need to show the page numbers for the Table of Contents in the word document(rtf). Below is the piece of snippet code which is not working. The left hand title are displayed properly and when we click on that it takes to the appropriate page but the page numbers are not getting displayed. Just for debugging purpose I tried generate-id() but it doesnt do anything.Any inputs on making this work would be appreciated.Thanks
<xsl:template match="html:td[contains(#class,'blabla')]">
<xsl:variable name="refId" select="substring-after(parent::html:tr/#id,'toc_')" />
<fo:table-cell border="none">
<fo:block text-align-last="justify">
<fo:basic-link internal-destination="{$refId}">
<xsl:apply-templates />
</fo:basic-link>
<xsl:text> </xsl:text>
<fo:leader leader-pattern="dots" leader-pattern-width="3pt" leader-length="20cm" />
<fo:page-number-citation ref-id="{$refId}"/>
</fo:block>
</fo:table-cell>
</xsl:template>
Salve, folks! I have a choice field in my sharepoint page with choices like this:
(1) Go
(2) Warning
(3) Stop
Now, I want that to appear in the list as an icon instead of text. I have a working jquery script for that, but it takes to long to search through all the list for the contained text, and it would be better to use xsl anyway because it renders before it is displayed.
So how can I accomplish this in xsl? Here is as far as I have gotten, as I am only learning xsl:
<xsl:stylesheet
xmlns:x="http://www.w3.org/2001/XMLSchema"
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
version="1.0"
exclude-result-prefixes="xsl msxsl ddwrt"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:SharePoint="Microsoft.SharePoint.WebControls"
xmlns:ddwrt2="urn:frontpage:internal">
<!-- Convert the Scope Field into an icon -->
<xsl:template match="FieldRef[#Name='Scope']">
<xsl:param name="thisNode" select="."/>
<xsl:choose>
<xsl:when test="$thisNode/#Scope='(1) Go'">
<td class="statusRating1"></td>
</xsl:when>
<xsl:when test="$thisNode/#Scope='(2) Warning'">
<td class="statusRating2"></td>
</xsl:when>
<xsl:when test="$thisNode/#Scope='(3) Stop'">
<td class="statusRating3"></td>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$thisNode/#Scope" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Here is the css I want to apply:
.statusRating1{background-image: url("/_layouts/custom/images/go.png"); }
.statusRating2{background-image: url("/_layouts/custom/images/warning.png"); }
.statusRating3{background-image: url("/_layouts/custom/images/stop.png"); }
Now, I've tried this with and without mode="Choice_body" or mode="MultiChoice_body and even Text_body, and have also tried adding <xsl:apply-templates />
but it never even seems to hook. The column is definitely named "Scope". Maybe I just have to add the right mode?
In firebug, I can see that the class is never added.
[update] I have noticed that in other places where I have used the template in this fashion, that the template never "took" unless it had the correct mode defined. However, I've googled the world over and can't find the right mode to use for a choice field. I even created a question for that, here. Also, the use of thisNode is from Microsoft's examples, where you can modify field types very easily (except in the case of this here choice field).
In order to define Custom Rendering for a SPFieldChoice field in template for mode attribute should be used value body
Template for modes with names Choice_body MultiChoice_body are not defined.
So, in your case template would look like this:
<xsl:template match="FieldRef[#Name='Scope']" mode="body">
Template mode attributes defined for rendering SharePoint fields are not documented, but you could find this information in %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LAYOUTS\XSL\fldtypes.xsl. See implementation of template PrintField for details.
Hope this helps,
Vadim
The fact that you have written a template isn't enough for this template ever to be executed.
And if it is selected for execution by the code of the XSLT built-in (default) templates, these templates don't know about any parameter named $thisNode, and don't pass such parameter to your template.
This means that the value of the$thisNode parameter when the template is initiated is the empty string -- therefore none of the xsl:when test conditions is satisfied and thus the xsl:otherwise is chosen.
Solution:
Either:
Have an explicit xsl:apply-templates in your code, that selects the nodes to be matched by the tempate, or:
Delete the <xsl:param> and replace in the code every occurence of $thisNode with ..
I need to grab the document library name in a webpartpages:dataformwebpart
I see the document library names in several places. Which one should I grab?
HeaderTitle="DocLib_23"
DetailLink="/sites/SiteCollection/Project_ABC/SubSite1/DocLib_23/Forms/AllItems.aspx"
Title="DocLib_23"
How do I create a param in xsl to grab the doc lib name from any one of the above?
i.e. Title or HeaderTitle
Some good Links.
http://msdn.microsoft.com/en-us/library/dd583143(office.11).aspx
Add these two line
<xsl:variable name="DocLibName" select="substring-before(substring-after($PageUrl, '/Forms/'), '/')" />
<xsl:param name="PageUrl"/>
set VIEWFLAG=1 (it should be in the properties windows)
Find this line and modify if you want Filter the webpart list
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
Change it to following
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[(#CustomerNo=$DocLibName)]"/>
You can use this to display
<xsl:value-of select="$DocLibName"> <br/>
<xsl:value-of select="$PageUrl"/><br/>
I'm using DataFormWebPart to display all announcements in the SharePoint site collections. It uses SPDataSouce with DataSourceMode set to CrossList and it works OK. The text of the announcement comes from the XML attribute:
<xsl:value-of disable-output-escaping="yes" select="#Body" />
Now I need to limit this text to, say, 250 characters. Of course, I cannot truncate it as a simple string as it could produce invalid HTML. I needed something like ddwrt:Limit but HTML aware.
Any ideas, please?
I think you want to display 250 characters in the page, please use this script
<xsl:if test="string-length(#Body) <= 250">
<xsl:value-of select="#Body"/>
</xsl:if>
<xsl:if test="string-length(#Body) > 250">
<xsl:value-of select="substring(#Body,0,250)"/>....
</xsl:if>
I found a very simple solution for this,try this instead!
<xsl:value-of select="substring(#Body, 1, 250 + string-length(substring-before(substring(#Body, 250),' ')))" />
This is my first time using XSLT. I'm trying to create a file that will convert an XML data file exported from a program I use to an HTML report.
One of the element's value is path to an image file, but the path generated is an absolute path such as
C:\Documents and Settings\me\Desktop\xml export\cd000402.jpg
but I want a relative path to just the file name.
Is there some way through the XLST file to parse out the file name?
XPath contains the substring-after function which returns the string following the first occurrence of another string. This isn't enough by itself, but a template such as the following might do it:
<xsl:template name="filename-only">
<xsl:param name="path" />
<xsl:choose>
<xsl:when test="contains($path, '\')">
<xsl:call-template name="filename-only">
<xsl:with-param name="path" select="substring-after($path, '\')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$path" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The set of string functions available is not terribly extensive, but I've found that it is good enough for most applications that you'll need in XSLT.
This is a little beyond the scope of the question, but Michael Kay has an excellent paper on using XSLT 2 to parse pure text into XML.
Yes, see a general LR(1) parser implemented in XSLT 2.0. (just in 245 lines).
I have implemented with it a parser for JSON and a parser for XPath 2.0 -- entirely in XSLT.
XSLT with the help of XPath 2.0 and its various string functions helps it deal with this type of things.
Example:
Assuming the path [to jpg file] mentioned in question comes from an xml snippet similar to
...
<For_HTML>
<Image1>
<Path>C:\Documents and Settings\me\Desktop\xml export\cd000402.jpg</Path>
<Description>Photo of the parking lot</Description>
<Width>123</Width>
...
</Image1>
</For_HTML>
XSLT snippet would look something like
<xsl:template match='//For_HTML/Image1'>
<img src='http://myNewServer.com/ImageBin/{substring-after(./Path,"\xml export\")}'
alt='{./Description}'
width=' .... you got the idea'
/>
</xsl:template>
Note: didn't have time to test; but that looks about right.
It is possible. I've developed the following script:
http://barsand.wordpress.com/2012/06/19/can-an-xslt-parse-a-string-of-text/