2012-11-10 58 views
1

我似乎无法继承xsl:use-attribute-sets。 Michael Kay在第6章中说过。XSLT元素> xsl:attribute-set - 页码。 269xsl:属性集不能从xsl:属性集正确继承

如果该属性组合也反复使用,它可能是 定义为在自己的权利的属性集,如:

<xsl:attribute-set name="ruled-table" use-attribute-set="full-width-table"> 
<xsl:attribute name="border">2</xsl:attribute> 
<xsl:attribute name="rules">cols</xsl:attribute> 
</xsl:attribute-set> 

EDIT 1:USE-属性 - 设置使用属性集可能是书中的一个TYPO;我使用XSL:USE-ATTRIBUTE-SETS

这对我不起作用。换句话说,在我的当前设置[通过Apache茧XSLT 2.0,导入styles.xsl成mypdf.xsl]的

结果
<table xsl:use-attribute-sets="ruled-table"> 
<tr>...</tr> 
</table> 

将属性的差集设置格表全角,而不是先前介导的设置联合的两个属性集。我只获取直接命名的属性,而不是命名属性集的父属性集。我可以通过做这样的事情来模拟效果:

<table xsl:use-attribute-sets="full-width-table ruled-table"> 
<tr>...</tr> 
</table> 

看来不过这应该是不必要的。有没有人遇到过这个问题?这里是styles.xsl:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" exclude-result-prefixes="xsl xs fo"> 

    <xsl:attribute-set name="fontstack"> 
    <xsl:attribute name="text-align">left</xsl:attribute> 
    <xsl:attribute name="font-size">10pt</xsl:attribute> 
    <xsl:attribute name="font-family">"TradeGothic-CondEighteen", "Trade Gothic Cond Eighteen", "Trade Gothic Condensed Eighteen", "Trade Gothic", "TradeGothic", "Trade-Gothic", "ArialNarrow", "Arial-Narrow", "Arial Narrow", Arial, sans-serif 
    </xsl:attribute> 
    <xsl:attribute name="color">black</xsl:attribute> 
    </xsl:attribute-set> 

    <xsl:attribute-set name="headers" xsl:use-attribute-sets="fontstack"> 
    <xsl:attribute name="font-size">18pt</xsl:attribute> 
    <xsl:attribute name="font-weight">bold</xsl:attribute> 
    <xsl:attribute name="space-after">7pt</xsl:attribute> 
    <xsl:attribute name="padding">12pt</xsl:attribute> 
    </xsl:attribute-set> 

    <xsl:attribute-set name="h2" xsl:use-attribute-sets="headers"> 
    <xsl:attribute name="padding">5pt</xsl:attribute> 
    </xsl:attribute-set> 

    <xsl:attribute-set name="h3" xsl:use-attribute-sets="headers"> 
    <xsl:attribute name="padding">2pt</xsl:attribute> 
    </xsl:attribute-set> 

</xsl:stylesheet> 

回答

1

有两个问题可能导致您的问题。

1)您指定的属性use-attribute-set在你的第一个例子中的xsl:attribute-set element,但它必须是复数use-attribute-sets

<xsl:attribute-set name="ruled-table" use-attribute-sets="full-width-table"> 
    <xsl:attribute name="border">2</xsl:attribute> 
    <xsl:attribute name="rules">cols</xsl:attribute> 
</xsl:attribute-set> 

2)在样式表中使用的是在xsl:attribute-set element属性xsl:use-attribute-sets ,但它必须是非名称空间限定属性use-attribute-sets

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" exclude-result-prefixes="xsl xs fo"> 

    <xsl:attribute-set name="fontstack"> 
     <xsl:attribute name="text-align">left</xsl:attribute> 
     <xsl:attribute name="font-size">10pt</xsl:attribute> 
     <xsl:attribute name="font-family">"TradeGothic-CondEighteen", "Trade Gothic Cond Eighteen", "Trade Gothic Condensed Eighteen", "Trade Gothic", "TradeGothic", "Trade-Gothic", "ArialNarrow", "Arial-Narrow", "Arial Narrow", Arial, sans-serif 
     </xsl:attribute> 
     <xsl:attribute name="color">black</xsl:attribute> 
    </xsl:attribute-set> 

    <xsl:attribute-set name="headers" use-attribute-sets="fontstack"> 
     <xsl:attribute name="font-size">18pt</xsl:attribute> 
     <xsl:attribute name="font-weight">bold</xsl:attribute> 
     <xsl:attribute name="space-after">7pt</xsl:attribute> 
     <xsl:attribute name="padding">12pt</xsl:attribute> 
    </xsl:attribute-set> 

    <xsl:attribute-set name="h2" use-attribute-sets="headers"> 
     <xsl:attribute name="padding">5pt</xsl:attribute> 
    </xsl:attribute-set> 

    <xsl:attribute-set name="h3" use-attribute-sets="headers"> 
     <xsl:attribute name="padding">2pt</xsl:attribute> 
    </xsl:attribute-set> 

</xsl:stylesheet> 
+0

非常感谢 - 我的问题已解决。为什么第二件事情是这样?为什么它需要成为非命名空间限定属性use-attribute-sets? –

+0

因为语言是这样定义的;通常XSLT元素本身位于XSLT命名空间'http:// www.w3.org/1999/XSL/Transform'中,这些元素上定义的属性不在命名空间中。 XSLT名称空间中的属性被定义为用于文字结果元素,而不是XSLT元素本身。 –

+1

根据规范,在xslt命名空间中的元素上使用xslt命名空间中的属性应该会导致错误。这些属性只能用于文字结果元素。 –