2012-08-28 51 views

回答

1

下面演示添加屬性(在此情況target)到a標記中的每一個,這些標記是ID爲navigation(因此對應於CSS中的#navigation)的元素下的子元素。來自原始標籤的所有內容和其他屬性都得到維護(儘管訂單可能不會 - 儘管這不應該成爲問題)。

<?xml version="1.0" encoding="UTF-8"?> 
<rules xmlns="http://namespaces.plone.org/diazo" 
     xmlns:css="http://namespaces.plone.org/diazo/css" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <after css:theme="#target" css:content="#navigation" /> 

    <xsl:template match="*[@id='navigation']//a"> 
     <xsl:copy> 
      <xsl:attribute name="target">_blank</xsl:attribute> 
      <xsl:copy-of select="@*" /> 
      <xsl:apply-templates /> 
     </xsl:copy> 
    </xsl:template> 
</rules> 

有附加條件,如果你想匹配特定a標記相應的調整match條件。 xsl:template將在所有標準重氮規則之後執行,因此如果您恰好改變了結果文檔中a標籤的結構,請確保相應地調整match條件。

這是在官方重氮文檔http://docs.diazo.org/en/latest/recipes/adding-an-attribute/index.html

1

不知道你的意思。 如果你想創建一個XSLT那份一切,但調整隻是「一」的DIV ID中的元素=「導航」你應該這樣做:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="html" /> 

<xsl:template match="@*|node()" priority="-1"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
    </xsl:template> 

<xsl:template match="//div[@id='navigation']//a"> 
    <a> 
     <xsl:attribute name='href'> 
      <xsl:value-of select='@href' /> 
     </xsl:attribute> 
     <!-- Change your content here --> 
    </a> 
</xsl:template> 

</xsl:stylesheet>