Sharepoint XSL - 将字符串分解为组成部分

发布于 2024-10-07 17:14:27 字数 525 浏览 0 评论 0原文

我正在使用启用了多重检查选项的“选择”网站栏,以便用户可以使用该栏中的多个选项来标记列表项。

然后,该列为内容查询 Web 部件中的设计功能提供支持 - 其中附加列选择以创建图像文件名。

  • Choice1
  • Choice2
  • Choice3
  • Choice4

变成

<img src="http://mysite/content-Choice1.jpg />

我遇到的问题是 XSL 解析器输入一个字符串,该字符串用分号 (;) 和散列 (#) 分隔选择值。如果勾选了所有 4 个选项,则输入 XSLT 解析器的字符串将是:

;#Choice1;#Choice2;#Choice3;#Choice4

如何处理该字符串并将每个选项分离到其自己的 XSL 变量中?

我已经尝试了各种 substring-before 函数,但我无法让任何东西工作。

I'm using a "choice" site column with the multiple-check option enabled so that users can tag a list item with several choices from the column.

This column then powers a design feature in a content query webpart - where the column choice is appended to create an image filename.

  • Choice1
  • Choice2
  • Choice3
  • Choice4

becomes

<img src="http://mysite/content-Choice1.jpg />

The problem I've got is that the XSL parser is fed a string which has semicolons (;) and hashes (#) separating the choice values. If all 4 options were ticked, the string fed into the XSLT parser would be:

;#Choice1;#Choice2;#Choice3;#Choice4

How can I work through the string and separate each choice into its own XSL variable?

I've tried various substring-before functions, but I can't get anything working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心作怪 2024-10-14 17:14:27

由于 XPath 1.0 不支持 tokenize() 函数,因此您必须自己完成所有工作。例如,您可以根据选择递归生成 元素:

<xsl:template name="RecurseConvertChoicesToImages">
    <xsl:param name="choices" />

    <xsl:variable name="token"
        select="substring-before($choices, ';#')" />
    <xsl:variable name="nextToken"
        select="substring-after($choices, ';#')" />

    <xsl:if test="$token">
        <img src="http://mysite/content-{$token}.jpg" />
    </xsl:if>
    <xsl:if test="$nextToken">
        <xsl:call-template name="RecurseConvertChoicesToImages">
            <xsl:with-param name="choices" select="$nextToken" />
        </xsl:call-template>
    </xsl:if>
</xsl:template>

Since XPath 1.0 does not support the tokenize() function, you'll have to do all the work yourself. For instance, you can generate the <img> elements recursively from the choices:

<xsl:template name="RecurseConvertChoicesToImages">
    <xsl:param name="choices" />

    <xsl:variable name="token"
        select="substring-before($choices, ';#')" />
    <xsl:variable name="nextToken"
        select="substring-after($choices, ';#')" />

    <xsl:if test="$token">
        <img src="http://mysite/content-{$token}.jpg" />
    </xsl:if>
    <xsl:if test="$nextToken">
        <xsl:call-template name="RecurseConvertChoicesToImages">
            <xsl:with-param name="choices" select="$nextToken" />
        </xsl:call-template>
    </xsl:if>
</xsl:template>
耀眼的星火 2024-10-14 17:14:27

我建议使用 JavaScript 来解析字符串,并相应地使用 JavaScript 显示图像。

I would recommend to use JavaScript to parse the string and accordingly display the image using JavaScript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文