我有一个保存列值的XML文件,我需要将它作为参数传递给我的xsl foreach语句。下面是我的实现,但我没有得到期望的结果:在XSL FO foreach语句中分配一个变量
XML
<PdfPrinter>
<Reports>
<Report>
<CreatedDate>2015-10-07T18:07:45</CreatedDate>
<LogType>ChangePassword</LogType>
<LoginID>ADMIN</LoginID>
<Name>XYZ</Name>
<AppVersion></AppVersion>
<System>OS</System>
<UserIPAddress>192.168.1.83</UserIPAddress>
<LoginDate />
<LogoutDate />
<Remarks></Remarks>
</Report>
<Report>
<CreatedDate>2015-10-07T18:09:54</CreatedDate>
<LogType>ChangePassword</LogType>
<LoginID>SUPERADMIN</LoginID>
<Name>ABC</Name>
<AppVersion></AppVersion>
<System>OS</System>
<UserIPAddress>192.168.1.83</UserIPAddress>
<LoginDate />
<LogoutDate />
<Remarks></Remarks>
</Report>
<Header>
<ReportID>AUD002</ReportID>
<GroupingColumn1>LoginID</GroupingColumn1>
<PrintedBy>SOS</PrintedBy>
<PrintedDate>2016-07-22T11:53:59.8826074Z</PrintedDate>
</Header>
</Reports>
</PdfPrinter>
XSLT
//variable declaration
<xsl:key name="Report" match="Report" use="$GroupingColumn" />
<xsl:variable name="GroupingColumn">
<xsl:value-of select="/PdfPrinter/Reports/Header/GroupingColumn1" />
</xsl:variable>
//Usage of the assigned variable
<xsl:for-each select="/PdfPrinter/Reports/Report[1]/*[local-name() !='$GroupingColumn']">
<fo:table-column column-width="proportional-column-width(4.77)"/>
</xsl:for-each>
在XML中,GroupingColumn1可能包含我应该任意值将它传递给我的XSL foreach。
**My XSL TABLE**
<fo:table border-bottom-width="5pt"
width="1200pt" border-bottom-color="rgb(0,51,102)">
<!--table header-->
<xsl:for-each select="/PdfPrinter/Reports/Report[1]/*[local-name() != 'LoginID']">
<fo:table-column column-width="proportional-column-width(4.77)"/>
</xsl:for-each>
<fo:table-header>
<fo:table-row height="20.81pt" display-align="center" overflow="hidden">
<xsl:for-each select="/PdfPrinter/Reports/Report[1]/*[local-name() != 'LoginID']">
<fo:table-cell text-align="center" border="rgb(0, 0, 0) solid 1pt" padding="2pt">
<fo:block color="rgb(0,0,0)" text-align="center" font-weight="normal">
<xsl:value-of select="name()"/>
</fo:block>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
</fo:table-header>
<!--table body-->
<fo:table-body>
<xsl:for-each
select="PdfPrinter/Reports/Report[generate-id() = generate-id(key('Report', LoginID)[1])]">
<fo:table-row>
<fo:table-cell number-columns-spanned="{count(*) - 1}">
<fo:block><xsl:apply-templates select="LoginID" /></fo:block>
</fo:table-cell>
</fo:table-row>
<xsl:for-each select="key('Report', LoginID)">
<fo:table-row display-align="before">
<xsl:for-each select="*[local-name() != 'LoginID']">
<fo:table-cell text-align="center"
border-top-color="rgb(0, 0, 0)"
border-top-style="solid" border-width="1pt" padding="2pt">
<fo:block>
<xsl:value-of select="."/>
</fo:block>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
</xsl:for-each>
</xsl:for-each>
</fo:table-body>
</fo:table>
在上表中,我已硬编码的列名作为登录ID,而不是,我想传递变量的名称和创建表。我能够打印GroupingColumn变量,但不知道为什么它不打印输出。
你XSL使得对你的输入XML没有意义。例如:你的XSL有一个xpath“/ PdfPrinter/Reports/Header/GroupingColumn1”,它不存在于XML中的任何地方,所以它不会返回任何内容,也无法诊断你的竞争信息的问题。 –
@KevinBrown:我正在实现基于XML中GroupingColumn1值的1级分组,我应该能够将GroupingColumn1值传递给我的XSL,如上面的代码片段所示。我认为这只是变量赋值,如果需要,我会发布完整的XSLT。请指教。谢谢。 –
任何帮助,非常感谢.. –