gpt4 book ai didi

diazo - 如何使用 Diazo 规则计算 href 值

转载 作者:行者123 更新时间:2023-12-02 22:23:35 25 4
gpt4 key购买 nike

我正在尝试更改 href某些<a>通过使用我从内容中选择的值计算 URL 来获取主题中的元素。但是,我根本不知道如何更改 href 属性。好像是 attributes <replace> 中的属性不被理解规则。

最终,我希望能够做如下事情:

<replace css:theme="a.languageswitcher" attributes="href">
<!-- use some XSL logic here to stitch together the new href -->
</replace>

所以下面的规则有效,但对我没用:

<copy attributes="href" css:theme="a.languageswitcher" css:content="#portal-logo" />

<merge attributes="href" css:theme="a.languageswitcher" css:content="#portal-logo" />

但是这个已经不行了,attributes="href"使得这条规则被忽略。

<replace attributes="href" css:theme="a.languageswitcher" css:content="#portal-logo" />

另一方面,如果我尝试重建 <a>元素,然后我遇到了@ross-patterson 在他的问题中描述的错误:Diazo - Conditionally add a class to a theme element :

    <replace theme="//a[@class='languageswitcher']">
<a class="languageswitcher">
<xsl:attribute name='href'>
foo
</xsl:attribute>
</a>
</replace>

产生错误:

XSLTApplyError: xsl:attribute: Cannot add attributes to an element if children have been already added to the element.

如何做到这一点?

最佳答案

像这样的东西应该可以工作:

<replace css:theme="a.languageswitcher">
<xsl:for-each css:select="a.languageswitcher">
<xsl:variable name="link">
http://example.com
</xsl:variable>
<a href="{$link}"><xsl:copy-of select="." /></a>
</xsl:for-each>
</replace>

关于diazo - 如何使用 Diazo 规则计算 href 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13316690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com