IBM Watson URL 重建函数 XSL 1.0

IBM Watson URL rebuild function XSL 1.0

我目前正在结合使用 IBM Watson Foundational Components 和 Sharepoint 服务器。

最大的问题似乎是管理路径的处理,Watson 将原始 URL 重建为自己的格式。使用以下代码完成转换。

      <xsl:variable name="url-tokens" select="str:tokenize($seed-urls, '&#10;')" />
      <xsl:variable name="fixed-urls">

        <!-- &#10; == newline -->
        <xsl:for-each select="$url-tokens">
          <xsl:variable name="url-parts" select="viv:url-decompose(.)" />
          <!-- Append a slash ("/") to the path, unless the path already has a slash, or ends in ".aspx" -->
          <xsl:variable name="fixed-path" select="concat($url-parts/path,viv:if-else(viv:match($url-parts/path, '(\.aspx|\/)$'),'','/'))" />

          <!-- Rebuild the URL, but use the io-sp protocol and the fixed path (constructed above) -->

          <xsl:value-of select="viv:url-build($crawl-protocol, '', '', $url-parts/host, $url-parts/port, $fixed-path, '')" />
          <xsl:value-of select="'&#10;'" />
        </xsl:for-each>
      </xsl:variable>

例如www.sharepoint-domain.com/IT/PM/page_name 分解为以下位:

然后使用以下结构重建此分解:

-> www.sharepoint-域.com/site/GUID_of_page_name

我们要做的是将分解结果更改为以下内容:

有没有办法使用 XSL 1.0 更改主机和路径的值? 这样 IT/PM/ 不属于路径而是属于主机。

Ps: viv:url-decompose(.) 从 $url-parts 创建:

不,那是不可能的,这些值是不可变的。

但是 您命名原始的 url 部分并创建您自己的值...

因此

首先,给第一个分解起个不同的名字:

<xsl:variable name="url-parts-temp" select="viv:url-decompose(.)" />

其次,创建一个变量url连同它所属的值:

<xsl:variable name="url">
    <path><xsl:value-of select="substring($url-parts-temp/path,string-length('it/pm')+2)"/></path>
    <host><xsl:value-of select="concat($url-parts-temp/host,$url-parts-temp/path)"/></host>
    <port>$url-parts-temp/port</port>
    <query>$url-parts-temp/query</query>
</xsl:variable>

第三,对变量$url:

使用exsl:node-set
<xsl:variable name="url-parts" select="exsl:node-set($url)" />

结果 现在您可以使用 url 部分,就像以前一样:

<xsl:value-of select="$url-parts/host" />
<xsl:value-of select="$url-parts/path" />