2017-02-17 28 views
0

我需要一些帮助,使用xsl-fo中的模板从xml数据生成pdf。xsl-fo表显示pdf生成的xml数据

我的问题是,我需要做一个表,只有一个项目(节点)的很多。

的exaple可能我看起来像这样的

<CollectionOfItems> 
<items> 
<title ID="someid" location="somelocation" price="someprice"/> 
<title ID="someid" location="somelocation" price="someprice"/> 
<title ID="someid" location="somelocation" price="someprice"/> 
</items> 
<items> 
<title ID="someid" location="somelocation" price="someprice"/> 
<title ID="someid" location="somelocation" price="someprice"/> 
<title ID="someid" location="somelocation" price="someprice"/> 
</items> 
</items> 
<title ID="someid" location="somelocation" price="someprice"/> 
<title ID="someid" location="somelocation" price="someprice"/> 
<title ID="someid" location="somelocation" price="someprice"/> 
<title ID="someid" location="somelocation" price="someprice"/> 
<title ID="someid" location="somelocation" price="someprice"/> 
<title ID="someid" location="somelocation" price="someprice"/> 
</items> 
</CollectionOfItems> 

每一个“项目”节点需要在一个单独的表中的XML ...所以我在XSL-FO表,看起来像做了一个表这

<fo:table width="100%" border-style="outset" border-width="2pt" background-repeat="no-repeat"> 
<fo:table-column/> 
<fo:table-column/> 
<fo:table-column/> 
<fo:table-body> 
    <xsl:for-each select="/Items/item/DataModification/Form/Tab/ModControl/Value/CompetenceConfig/Chapters/Chapter"> 
     <xsl:variable name="Chapter" select="."/> 
     <fo:table-row> 
      <fo:table-cell border-style="inset" border-width="2pt" padding="2pt" background-repeat="repeat" display-align="center"> 
       <fo:block> 
        <xsl:value-of select="@ID"/> 
       </fo:block> 
      </fo:table-cell> 
      <fo:table-cell border-style="inset" border-width="2pt" padding="2pt" background-repeat="repeat" display-align="center"> 
       <fo:block> 
        <xsl:value-of select="@location"/> 
       </fo:block> 
      </fo:table-cell> 
      <fo:table-cell border-style="inset" border-width="2pt" padding="2pt" background-repeat="repeat" display-align="center"> 
      <fo:block> 
       <xsl:value-of select="@price"/> 
      </fo:block> 
      </fo:table-cell> 
     </fo:table-row> 
    </xsl:for-each> 
</fo:table-body> 

这有点儿工作而是获得例如一个“项目”节点与项目内的每个表我得到了3“项目”,看起来在S节点3台AME。如何显示第一个表格中的第一个“节点”项目,第二个表格中的第二个“项目”节点等等?我真的很感激任何帮助。我一直在努力解决这个问题,我对xsl-fo是新手。

非常感谢!

+0

显示我们这个在您的XSL: /项目/产品/ DataModification /表格/标签/ ModControl /价值/ CompetenceConfig /章节/章节 然后提供XML甚至不接近具有结构(也它上面的模板)是毫无价值的。没有人可以在你工作的环境中猜测。 –

+0

因此,为了您进一步解释并根据您的意见进行解释......您是否想要六张桌子?第一行将有三行,第二行三行。第三排,第四排,第五排和第六排各一个?你在问什么? –

+0

对不起Kevin,我打算把它改成/ CollectionOfItems/items/title。 – jcolon

回答

1

这样的事情呢?不知道你有什么其他和纠正你在你的XML有一个错误....

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
    <xsl:template match="/"> 
     <fo:root> 
      <fo:layout-master-set> 
       <fo:simple-page-master master-name="page" page-width="8.5in" page-height="11in" margin-top="0.5in" margin-bottom="0.5in" margin-left="0.5in" margin-right="0.5in"> 
        <fo:region-body region-name="body" margin-top="0.5in" margin-bottom="0.5in" margin-left="0.5in" margin-right="0.5in"/> 
       </fo:simple-page-master> 
      </fo:layout-master-set> 
      <fo:page-sequence master-reference="page"> 
       <fo:flow flow-name="body"> 
        <xsl:apply-templates/> 
       </fo:flow> 
      </fo:page-sequence> 
     </fo:root> 
    </xsl:template> 
    <xsl:template match="items"> 
     <fo:block space-before="6pt" border-top="3pt solid green"> 
      <fo:table> 
       <fo:table-body> 
        <xsl:apply-templates/> 
       </fo:table-body> 
      </fo:table> 
     </fo:block> 
    </xsl:template> 
    <xsl:template match="title"> 
     <fo:table-row> 
      <xsl:apply-templates select="@*"/> 
     </fo:table-row> 
    </xsl:template> 
    <xsl:template match="@ID | @location | @price"> 
     <fo:table-cell border="1pt solid black"> 
      <fo:block> 
       <xsl:value-of select="."/> 
      </fo:block> 
     </fo:table-cell> 
    </xsl:template> 
</xsl:stylesheet> 

此息率:

enter image description here

这有每个“项目”创建一个表模板标记,每个“标题”标记的行和“标题”标记中的每个属性的单元格。我相信这就是你想要的。

+3

解析XML处理器可能以任何顺序向XSLT处理器呈现属性。在一般情况下,按照您希望的顺序选择属性会更安全。在这种情况下,您甚至可以在处理它们时按名称对属性进行排序。然后,再次,在一个封闭的系统中,您可以在其中生成XML,并且知道每件事物的工作原理,然后按照预期的顺序处理这些属性,就像他们在这里一样。 –