我是 XSLT 编程的新手,正在努力解决以下问题:
XML:
<All_Results>
<Result>
<url>http://server/sites/sitecoll/library/Folder/NewFolder/test v1.0.docx</url>
<hithighlightedproperties>
<HHUrl>SomeValue1</HHUrl>
</hithighlightedproperties>
<isdocument>True</isdocument>
<serverredirectedurl>SomeValue</serverredirectedurl>
</Result>
<Result>
<url>http://server/sites/sitecoll/library/NewFolder1/test v2.0.docx</url>
<hithighlightedproperties>
<HHUrl>SomeValue1</HHUrl>
</hithighlightedproperties>
<isdocument>True</isdocument>
<serverredirectedurl>SomeValue</serverredirectedurl>
</Result>
<Result>
<url>http://server/sites/sitecoll/library/NewFolder/test v1.0.docx</url>
<hithighlightedproperties>
<HHUrl>SomeValue1</HHUrl>
</hithighlightedproperties>
<isdocument>False</isdocument>
<serverredirectedurl>SomeValue1</serverredirectedurl>
</Result>
......
......
以下是要求:
对于每个“结果”部分,如果 (“isdocument” node = True),则读取“url”节点并在其值中获取 'library/' 之后的子字符串。从此输出中,获取最后一次出现“/”之前的子字符串。(使用单独的模板来实现)例如,对于第一个“Result”,它将是“Folder/NewFolder”。最后,在此输出之前和之后连接硬编码字符串,并将“HHUrl”和“ServerRedirectUrl”的值替换为“Results”下每个“Result”的最终输出。
输出
<All_Results>
<Result>
<url>http://server/sites/sitecoll/library/Folder/NewFolder/test v1.0.docx</url>
<hithighlightedproperties>
<HHUrl>http://SomeHardCodedString1/Folder/NewFolder/SomeHardCodedString2</HHUrl>
</hithighlightedproperties>
<isdocument>True</isdocument>
<serverredirectedurl>
http://SomeHardCodedString1/Folder/NewFolder/SomeHardCodedString2
</serverredirectedurl>
</Result>
<Result>
<url>http://server/sites/sitecoll/library/NewFolder1/test v2.0.docx</url>
<hithighlightedproperties>
<HHUrl>http://SomeHardCodedString1/NewFolder1/SomeHardCodedString2</HHUrl>
</hithighlightedproperties>
<isdocument>True</isdocument>
<serverredirectedurl>http://SomeHardCodedString1/NewFolder1/SomeHardCodedString2
</serverredirectedurl>
</Result>
<Result>
<url>http://server/sites/sitecoll/library/NewFolder/test v1.0.docx</url>
<hithighlightedproperties>
<HHUrl>SomeValue1</HHUrl>
</hithighlightedproperties>
<isdocument>False</isdocument>
<serverredirectedurl>SomeValue1</serverredirectedurl>
</Result>
......
......
我已经修剪了原始 XML 输出以简化需求,并有一个与原始 XML 相关联的长而复杂的 XLST。目标是在“HHUrl”字符串呈现为 HTML 之前动态修改它。对于这个特殊要求,我创建并嵌入了以下代码,它部分工作:
<xsl:template name="stripLast">
<xsl:param name="pText"/>
<xsl:param name="pDelim" select="'/'"/>
<xsl:if test="contains($pText, $pDelim)">
<xsl:value-of select="substring-before($pText, $pDelim)"/>
<xsl:if test="contains(substring-after($pText, $pDelim), $pDelim)">
<xsl:value-of select="$pDelim"/>
</xsl:if>
<xsl:call-template name="stripLast">
<xsl:with-param name="pText" select=
"substring-after($pText, $pDelim)"/>
<xsl:with-param name="pDelim" select="$pDelim"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="All_Results/Result/hithighlightedproperties/HHUrl">
<xsl:param name="staticUrl" select=" 'https://SomeHardCodedString1/' "/>
<xsl:copy>
<xsl:variable name="urlValue" select="string(.)"/>
<xsl:variable name="s" select="substring-after($urlValue, 'Portal/')"/>
<xsl:variable name="qsValue">
<xsl:call-template name="stripLast">
<xsl:with-param name="pText" select="$s"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat($staticUrl, $qsValue, 'SomeHardCodedString2')"/>
</xsl:copy>
</xsl:template>
任何帮助将不胜感激。
谢谢,
SharePoint 开发。