10

XSLT 自体に属性セットがあることは知っていますが、そのために強制的に使用する必要があります。

<xsl:element name="fo:something">

出力したいたびに

<fo:something>

鬼ごっこ。XSL-FO 仕様に、FO 出力のすべてのテーブルのデフォルトの属性セット (マージン、パディングなど) を指定できるものはありますか?

基本的に、私は CSS の機能を探していますが、HTML ではなく FO 出力を探しています。

4

2 に答える 2

11

いいえ、xsl:elementを使用する必要はありません。use-attribute-sets属性をXSLT名前空間に配置すると、リテラルの結果要素に表示される可能性があるため、次のように使用できます。

<fo:something xsl:use-attribute-sets="myAttributeSet">

CSS機能に近いものが必要な場合は、処理の最後に、必要な属性を追加する別のXSLT変換を追加できます。再帰的なID変換から始めて、変更する要素に一致するテンプレートを追加できます。以下の小さな例を参照してください。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:attribute-set name="commonAttributes">
    <xsl:attribute name="common">value</xsl:attribute>
  </xsl:attribute-set>
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="someElement">
    <xsl:copy use-attribute-sets="commonAttributes">
      <xsl:attribute name="someAttribute">someValue</xsl:attribute>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
于 2009-06-11T07:57:50.770 に答える
0

XSLT 2.0 には、別のオプションもあります。次のテンプレートは別のファイルにすることができます。FO 構造を生成する元の xsl ファイルにこのファイルを含めるだけで済みます。

<xsl:transform 
    version="2.0"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/" priority="1000">
        <!-- Store generated xsl-fo document in variable-->
        <xsl:variable name="xsl-fo-document">
            <xsl:next-match/>
        </xsl:variable>

        <!-- Copy everything to result document and apply "css" -->
        <xsl:apply-templates select="$xsl-fo-document" mode="css"/>
    </xsl:template>

    <xsl:template match="@*|node()" priority="1000" mode="css">
        <xsl:param name="copy" select="true()" tunnel="yes"/>
        <xsl:if test="$copy">
            <xsl:copy>
                <xsl:next-match>
                    <xsl:with-param name="copy" select="false()" tunnel="yes"/>
                </xsl:next-match>
                <xsl:apply-templates select="@*|node()" mode="css"/>
            </xsl:copy>
            </xsl:if>
    </xsl:template>

    <!-- **************************** -->
    <!-- CSS Examples (e.g. fo:table) -->
    <!-- **************************** -->

    <xsl:template match="fo:table-cell[not(@padding)]" mode="css">
        <xsl:attribute name="padding" select="'2pt'"/>
        <xsl:next-match/>
    </xsl:template>

    <xsl:template match="fo:table-header/fo:table-row/fo:table-cell" mode="css">
        <xsl:attribute name="color" select="'black'"/>
        <xsl:attribute name="font-style" select="'bold'"/>
        <xsl:next-match/>
    </xsl:template>

</xsl:transform>
于 2012-05-10T08:24:20.527 に答える