我有一個保存列值的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。請指教。謝謝。 –
任何幫助,非常感謝.. –