我是一名新手XSL编程人员,我想这是一个简单的问题: 如何获取不带路径的文件名? 目前我的代码看起来像这样,我得到了整个路径: Result.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<All_Results>
<Result>
<id>1</id>
<workid>144</workid>
<rank>100000000</rank>
<title>Test Dokument</title>
<author_multival>Test</author_multival>
<author>Test</author>
<size>34185</size>
<url>https://test.test.com/docs/globalit/Lists/Documents/Datumtest/Test.docx</url>
<urlEncoded>https%3A%2F%2Ftest%2Etest%2Ecom%2Fdocs%2Fglobalit%2FLists%2FDocuments%2FDatumtest%2FTest%2Edocx</urlEncoded>
<description></description>
<write>5/3/2013</write>
<sitename>https://test.test.com/docs/globalit/Lists/Documents/Datumtest</sitename>
<collapsingstatus>0</collapsingstatus>
<hithighlightedsummary>Noch mehr text Noch mehr text <ddd /> </hithighlightedsummary>
<hithighlightedproperties>
<HHTitle>Test Dokument</HHTitle>
<HHUrl>https://test.test.com/docs/globalit/Lists/Documents/Datumtest/Test.docx</HHUrl>
</hithighlightedproperties>
<contentclass>STS_ListItem_DocumentLibrary</contentclass>
<isdocument>True</isdocument>
<picturethumbnailurl></picturethumbnailurl>
<serverredirectedurl>https://test.test.com/docs/globalit/_layouts/WordViewer.aspx?id=/docs/globalit/Lists/Documents/Datumtest/Test.docx&DefaultItemOpen=1</serveedirectedurl>
<doclanguage>German</doclanguage>
<doctitle>Test</doctitle>
<docauthor>Team</docauthor>
<revisiondate>5/3/2013</revisiondate>
<filename>Test.docx</filename>
<fileextension>DOCX</fileextension>
<imageurl imageurldescription="Microsoft Word">/_layouts/images/icdocx.png</imageurl>
</Result>
</All_Results>
result.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="TotalResults" />
<xsl:template match="NumberOfResults" />
<xsl:template name="DisplayString">
<xsl:param name="str" />
<xsl:if test='string-length($str) > 0'>
<xsl:value-of select="$str" />
</xsl:if>
</xsl:template>
<xsl:template name="HitHighlighting">
<xsl:param name="hh" />
<xsl:apply-templates select="$hh"/>
</xsl:template>
<xsl:template name="ResultPreviewToolTip">
<xsl:param name="contentclass" />
<xsl:param name="picturethumbnailurl" />
<xsl:param name="url" />
<xsl:param name="title" />
<xsl:param name="hithighlightedsummary" />
<xsl:param name="description" />
<xsl:param name="version" />
<xsl:choose>
<xsl:when test="$contentclass[. = 'STS_ListItem_PictureLibrary'] and $picturethumbnailurl[. != '']">
<div>
<a href="{$url}" title="{$title}">
<img src="{$picturethumbnailurl}" alt="" />
</a>
</div>
</xsl:when>
<xsl:when test="contains( $url, 'jpg' ) or contains( $url, 'jpeg' ) or contains( $url, 'gif' ) or contains( $url, 'JPG' ) or contains( $url, 'JPEG' ) or contains( $url, 'GIF' )">
<div>
<img src="/_layouts/AssetUploader.aspx?Size=Medium&ImageUrl={$url}" alt="" />
</div>
</xsl:when>
<xsl:otherwise>
<div>
<xsl:choose>
<xsl:when test="$hithighlightedsummary[. != '']">
<b>Preview:</b>
<br/>
<xsl:call-template name="HitHighlighting">
<xsl:with-param name="hh" select="$hithighlightedsummary" />
</xsl:call-template>
</xsl:when>
<xsl:when test="$description[. != '']">
<b>Preview:</b>
<br/>
<xsl:value-of select="$description"/>
</xsl:when>
<xsl:otherwise>
No preview available
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="DisplayString">
<xsl:with-param name="str" select="$version" />
<xsl:with-param name="text" select="'Version: '" />
<xsl:with-param name="stringcolor" select="'#808080'" />
</xsl:call-template>
</div >
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="Result">
<xsl:variable name="tdClass">
<xsl:if test="(position() mod 2 = 0)">
<xsl:value-of select="'even'" />
</xsl:if>
<xsl:if test="(position() mod 2 = 1)">
<xsl:value-of select="'odd'" />
</xsl:if>
</xsl:variable>
<tr>
<td class="{$tdClass}">
<a href="#" class="tooltip">
<img>
<xsl:attribute name="src">
<xsl:value-of select="imageurl"/>
</xsl:attribute>
</img>
<span>
<xsl:call-template name="ResultPreviewToolTip">
<xsl:with-param name="contentclass" select="contentclass" />
<xsl:with-param name="description" select="description" />
<xsl:with-param name="hithighlightedsummary" select="hithighlightedsummary" />
<xsl:with-param name="picturethumbnailurl" select="picturethumbnailurl" />
<xsl:with-param name="title" select="title" />
<xsl:with-param name="url" select="url" />
<xsl:with-param name="version" select="version" />
</xsl:call-template>
</span>
</a>
</td>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="url" disable-output-escaping="yes" />
</xsl:attribute>
<xsl:value-of select="filename"/>
</a>
</td>
<td class="{$tdClass}">
<a>
<xsl:attribute name="href">
<xsl:value-of select="url" disable-output-escaping="yes" />
</xsl:attribute>
<xsl:choose>
<xsl:when test="doctitle != ''">
<xsl:value-of select="doctitle"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="title"/>
</xsl:otherwise>
</xsl:choose>
</a>
</td>
<td class="{$tdClass}">
<xsl:choose>
<xsl:when test="docauthor != ''">
<xsl:value-of select="docauthor"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="author"/>
</xsl:otherwise>
</xsl:choose>
</td>
<td class="{$tdClass}">
<xsl:value-of select="revisiondate" />
</td>
<td class="{$tdClass}">
<xsl:value-of select="doclanguage"/>
</td>
<td class="{$tdClass}">
<a>
<xsl:attribute name="href">
<xsl:value-of select="sitename" disable-output-escaping="yes" />
</xsl:attribute>
<img src="/_layouts/images/breadcrumbbutton.png" style="border-style: none" />
</a>
<xsl:call-template name="ShowVersionHistory" />
</td>
</tr>
</xsl:template>
<xsl:template name="ShowVersionHistory">
<!-- First, encode Url -->
<xsl:variable name="EncodedUrl">
<xsl:value-of disable-output-escaping="yes" select="ddwrt:UrlEncode(url)" />
</xsl:variable>
<!-- does only work for office docuemnts -->
<xsl:if test="string-length(serverredirectedurl) > 0">
<!-- get web url from office web app link -->
<xsl:variable name="WebUrl">
<xsl:value-of select="substring-before(serverredirectedurl, '_layouts')"/>
</xsl:variable>
<!-- create link -->
<xsl:variable name="FinalLink">
<xsl:value-of select="$WebUrl"/>
<xsl:text>_layouts/Versions.aspx?FileName=</xsl:text>
<xsl:value-of select="$EncodedUrl"/>
</xsl:variable>
<a href="{$FinalLink}" target="_blank" Title="Version History">
<img src="/_layouts/images/versions.gif" style="border-style: none" />
</a>
</xsl:if>
</xsl:template>
<xsl:template match="/">
<table class="searchresult">
<tr>
<th width="18"></th>
<th>Filename</th>
<th>Title</th>
<th>Author</th>
<th>Revision Date</th>
<th>Language</th>
<th>Actions</th>
</tr>
<xsl:apply-templates />
</table>
</xsl:template>
</xsl:stylesheet>
我只需要获取像Test.dotx或Test.xlsx这样的文件。 我尝试了使用
<xsl:value-of select="substring-after-last($url, '/')" disable-output-escaping="yes" />
,但是出现了错误。
我该怎么做?如何解决我的问题?
感谢您的支持。
敬礼,
马蒂亚斯
<a href="{tokenize(url, '/')[last()]}"><xsl:value-of select="tokenize(url, '/')[last()]"/></a>
。 - Martin Honnencode
<All_Results> <Result> <id>1</id> <workid>144</workid> <rank>100000000</rank> <title>测试文档</title> <author_multival>测试</author_multival> <author>测试</author> <size>34185</size> <url>https://test.test.com/docs/globalit/Lists/Documents/Datumtest/Test.docx</url></Result></All_Results>code
(在URL中ht后面没有空格,但最好看到它) - Smeets