我試圖通過使用從內容中選擇的值計算URL來更改主題中某些<a>
元素的href
。但是,我無法弄清楚如何根本改變href屬性。看起來attributes
屬性在<replace>
規則中不被理解。如何使用重氮規則計算href值
最終,我希望能夠做一些事情,如:
<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>
元素,然後我碰上通過@羅斯 - 帕特森在他的問題描述的錯誤: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.
這怎麼辦?
這是真正棘手IMO ....面臨着同樣的問題 - 大量的努力後,我放棄了,只是確信的聯繫是在我的Plone內容的地方,所以我可以用一個規則把它拉在 –
Danimal