English 中文(简体)
页: 1
原标题:xml-fo pdf table : colspan when the number of columns is dynamic

I m generating a table in a pdf document using xml-fo.
The number of columns is dynamic. Columns are only displayed when tests are passing.
In tests I m using variables like $var1, $var2, ... that point to xml nodes.

我这样说。

 <xsl:element name="fo:table-row">
    <xsl:element name="fo:table-cell" use-attribute-sets="table-cell">
        <xsl:attribute name="number-columns-spanned"> **???** </xsl:element>
        <xsl:element name="fo:block">Text that spans over columns</xsl:element>
    </xsl:element>
 </xsl:element>
 <xsl:element name="fo:table-row" use-attribute-sets="headerRow"> 
    <xsl:element name="fo:table-cell" use-attribute-sets="table-cell">
       <xsl:element name="fo:block">some value here</xsl:element>
    </xsl:element>
    <xsl:if test="$var1">
       <xsl:element name="fo:table-cell" use-attribute-sets="table-cell">
          <xsl:element name="fo:block">maybe some value here 2</xsl:element>
       </xsl:element>
    </xsl:if>
    <xsl:if test="$var2">
       <xsl:element name="fo:table-cell" use-attribute-sets="table-cell">
          <xsl:element name="fo:block">maybe some value here 3</xsl:element>
       </xsl:element>
    </xsl:if>
    ...
</xsl:element>

I m expanding the 1st row to span all over the columns. "number-columns-spanned" is variable and depends on the number of test that are passing.
Is there an easy way to dynamically extract the number of conditions that are passing in order to correctly define the attribute number-columns-spanned?

最佳回答

你们可以通过这样的表述来计算变量的内容:

count($var1 | $var2 | $var3 | ...)

假设你们的每个变量,就是一种可能无法避免的组合。 如果您的变量是真实的/虚假的数值,那么你就可以利用XSL中的错误0和真实性(至少使用译员Im):

$var1 + $var2 + $var3 + ...

如果这些数值为t node set and aren t booleans,则首先将其转化成机器人:

boolean($var1) + boolean($var2) + boolean($var3) + ...

这不是处理该问题的非常明智的方法,而是行之有效的。

According to the XPath spec, booleans are actual due to behave this way whenposition to numerics. Good!

问题回答

暂无回答




相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签