XSL FO表除外

问题描述 投票:0回答:2

我对.XSL文件有问题,我需要用此值制作一个表,但是对于我的文件,我做了一个没有列的表,我想让它们成为一个包含“año”数据的列另一个带有“ titulo”的数据。我不知道该怎么做。这是我的代码:

<xsl:template match="catalogo">
<fo:table border="solid" border-collapse="collapse" table-layout="fixed" width="100%">
  <fo:table-body>
    <xsl:apply-templates/>
  </fo:table-body>
</fo:table>
</xsl:template>

<xsl:template match="cd">
  <fo:table-row>
    <fo:table-cell border="1pt solid black">
      <xsl:if test="año &gt; 2000">
      <fo:block color="green">
      <xsl:value-of select="titulo"/>
      </fo:block>
      </xsl:if>

      <xsl:if test="año &lt; 2000">
      <fo:block color="red">
      <xsl:value-of select="titulo"/>
      </fo:block>
      </xsl:if>

      <xsl:if test="año='2000'">
      <fo:block color="black">
      <xsl:value-of select="titulo"/>
      </fo:block>
      </xsl:if>

      <fo:block>
      <xsl:value-of select="año"/>
      </fo:block>
      </fo:table-cell>
      </fo:table-row>
</xsl:template>
</xsl:stylesheet>

其结果是:

“

xml xslt xsl-fo
2个回答
0
投票

谁知道你想要什么,但总的来说是猜测:

<xsl:template match="cd">
  <fo:table-row>
    <!-- add a table cell for ano -->
    <fo:table-cell>
       <fo:block><xsl:value-of select="año"/></fo:block>
    </fo:table-cell>
    <fo:table-cell border="1pt solid black">
      <xsl:if test="año &gt; 2000">
      <fo:block color="green">
      <xsl:value-of select="titulo"/>
      </fo:block>
      </xsl:if>

      <xsl:if test="año &lt; 2000">
      <fo:block color="red">
      <xsl:value-of select="titulo"/>
      </fo:block>
      </xsl:if>

      <xsl:if test="año='2000'">
      <fo:block color="black">
      <xsl:value-of select="titulo"/>
      </fo:block>
      </xsl:if>

      <fo:block>
      <xsl:value-of select="año"/>
      </fo:block>
      </fo:table-cell>
      </fo:table-row>
</xsl:template>

0
投票

不是您问题的答案,但您可以将color的选择简化为:

<fo:block>
  <xsl:attribute name="color">
    <xsl:choose>
      <xsl:when test="año &gt; 2000">green</xsl:when>
      <xsl:when test="año &lt; 2000">red</xsl:when>
      <xsl:otherwise>black</xsl:otherwise>
    </xsl:choose>
  </xsl:attribute>
  <xsl:value-of select="titulo"/>
</fo:block>

如果我们知道您使用的是XSLT 2.0或XSLT 3.0,则可能会更短。

© www.soinside.com 2019 - 2024. All rights reserved.