6

属性「style」を持つxmlノード「item」があります。これは「Header1」です。ただし、このスタイルは変更される可能性があります。xsl:foを介して生成された、PDFでこれがどのように表示されるかを定義するHeader1という名前の属性セットがあります。

これは機能します(use-attribute-setsはfo:table-cellノードでインラインで言及されています):

<xsl:template match="item[@type='label']">
    <fo:table-row>
        <fo:table-cell xsl:use-attribute-sets="Header1">            
             <fo:block>
                 <fo:inline font-size="8pt" >
                    <xsl:value-of select="." />
                </fo:inline>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
</xsl:template>

しかし、これはそうではありません(たとえば、属性@styleはHeader2になることもあるため、xsl:attributeを使用します)。エラーは発生せず、PDFは作成されますが、属性は適用されません。

<xsl:template match="item[@type='label']">
    <fo:table-row>
        <fo:table-cell>         
             <xsl:attribute name="xsl:use-attribute-sets">
                 <xsl:value-of select="@style" />
             </xsl:attribute>
             <fo:block>
                 <fo:inline font-size="8pt" >
                    <xsl:value-of select="." />
                </fo:inline>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
</xsl:template>

誰かが理由を知っていますか?そして、できれば長いxsl:ifまたはxsl:whenを使わずに、これをどのように達成できるでしょうか。

4

3 に答える 3

6

http://www.w3.org/TR/xslt#attribute-setsから

属性セットは、xsl:element、xsl:copy [...]、またはxsl:attribute-set要素でuse-attribute-sets属性を指定することによって使用されます。

http://www.w3.org/TR/xslt#section-Creating-Elements-with-xsl:elementから

<!-- Category: instruction -->
<xsl:element
  name = { qname }
  namespace = { uri-reference }
  use-attribute-sets = qnames>
  <!-- Content: template -->
</xsl:element>

そしてhttp://www.w3.org/TR/xslt#copying

<!-- Category: instruction -->
<xsl:copy
  use-attribute-sets = qnames>
  <!-- Content: template -->
</xsl:copy>

したがって、AVT(動​​的に定義)にすることはできないことは明らかです。

:リテラル結果要素についての仕様によると、属性セットは、リテラル結果要素にxsl:use-attribute-sets属性を指定することによっても使用できます。AVTを許可することについて漠然としたことはめったにありません。いいえと仮定します。

2番目の例について:そのテンプレートを使用して、結果ツリーに「xsl:use-attribute-sets」属性を追加します。XSLTプロセッサによって解釈されません。

それでは、解決策は何ですか?「xsl:use-attribute-sets」を削除する必要があります。「@style」のテンプレートルールを適用し、そこに必要な属性を生成します。

于 2010-06-08T16:33:03.947 に答える
0

Use a variable to define style, a variable for true, a variable for false, and a variable to reference either one dynamically using string concatenation:

<xsl:variable name="style">
  <xsl:value-of select="concat(boolean(@style),boolean(not(@style) ) )"/>
</xsl:variable>

<xsl:variable name="falsetrue" select="'foo'"/>
<xsl:variable name="truefalse" select="'bar'"/>
<!--...-->


<xsl:value-of select="//xsl:variable/@select[../@name='style']"/>

Or you can have the templates match themselves and call them using the value of "style":

<xsl:template name="Header1" match="xsl:template[@name='Header1']"/>

<xsl:template name="Header2" match="xsl:template[@name='Header2']"/>
于 2012-05-22T00:28:20.213 に答える
0

試してみてください

<fo:table-cell xsl:use-attribute-sets="{@style}">
于 2010-06-08T16:47:03.573 に答える