从 XML 中的表中选择一些行后 + XSLT - 导出为 pdf
好的。这是我的情况。我有包含数据的 XML 文件和包含格式数据的 XSLT。我知道我需要 XSL-FO 才能转换为 PDF 格式。但我需要在选择一行包含有关人员的数据后,通过 XSL-FO 将其转换为 pdf。
这是我的代码
<?xml version="1.0" encoding="iso-8859-2" ?>
<?xml-stylesheet type="text/xsl" href="pacienti.xsl"?>
<pacienti>
<pacient>
<id>1</id>
<meno>Jozef</meno>
<priezvisko>Hubáč</priezvisko>
<pohlavie>M</pohlavie>
<DN-den>1</DN-den>
<DN-mesiac>1</DN-mesiac>
<DN-rok>1991</DN-rok>
<pocetRokov>20</pocetRokov>
<adresa>Lipová 20, Banská Bystrica</adresa>
<statnaPrislusnost>SK</statnaPrislusnost>
<rodneCislo>910101/1234</rodneCislo>
<zdravotnaPoistovna>25</zdravotnaPoistovna>
<diagnoza>E120</diagnoza>
</pacient>
<pacient>
<id>2</id>
<meno>Peter</meno>
<priezvisko>Imrią</priezvisko>
<pohlavie>M</pohlavie>
<DN-den>5</DN-den>
<DN-mesiac>2</DN-mesiac>
<DN-rok>1990</DN-rok>
<pocetRokov>21</pocetRokov>
<adresa>Pietrová 333, Banská ©tiavnica</adresa>
<statnaPrislusnost>SK</statnaPrislusnost>
<rodneCislo>900205/5658</rodneCislo>
<zdravotnaPoistovna>21</zdravotnaPoistovna>
<diagnoza>A23</diagnoza>
</pacient>
</pacienti>
,这是 XSLT 代码
<body onload="javascript:document.getElementById('vsetko').style.display = 'block'; document.getElementById('podlaPoctuRokovOdNajmensieho').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajvecsieho').style.display = 'none'; document.getElementById('podlaPohlavia').style.display = 'none'; document.getElementById('podlaStatnejPrislusnosti').style.display = 'none';">
<div id="vsetko" style="position:relative; top:70px;">
<h2>Databáza pacientov (zoradená podµa ID)</h2>
<table border="2" id="zvyraznene" width="100%">
<tr class="tabulcicka" >
<th bgcolor="yellow">Id:</th>
<th>Priezvisko, meno:</th>
<th>Dátum narodenia:</th>
<th>Pohlavie</th>
<th>©tátna prísluąnos»</th>
<th>Adresa</th>
<th>Rodné číslo</th>
<th>Zdravotná pois»ovňa</th>
<th>Diagnóza</th>
</tr>
<xsl:for-each select="pacienti/pacient">
<xsl:sort select="id" data-type="number">
</xsl:sort>
<tr onmouseover="this.className='zvyraznene'" onmouseout="this.className='normalne'">
<td>
<xsl:value-of select="id">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="priezvisko">
</xsl:value-of>,<xsl:value-of select="meno">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="DN-den">
</xsl:value-of>.<xsl:value-of select="DN-mesiac">
</xsl:value-of>.<xsl:value-of select="DN-rok">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="pohlavie">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="statnaPrislusnost">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="adresa">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="rodneCislo">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="zdravotnaPoistovna">
</xsl:value-of>
</td>
<td align="center" >
<xsl:value-of select="diagnoza">
</xsl:value-of>
</td>
</tr>
</xsl:for-each>
</table>
</div>
<div id="menu">
<input type="button" class="tlacitko" value="Vąetci pacienti" onclick="javascript:document.getElementById('vsetko').style.display = 'block'; document.getElementById('podlaPoctuRokovOdNajmensieho').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajvecsieho').style.display = 'none'; document.getElementById('podlaPohlavia').style.display = 'none'; document.getElementById('podlaStatnejPrislusnosti').style.display = 'none';">
</input>
<input type="button" class="tlacitko" value="Zoraď podµa pohlavia" onclick="javascript:document.getElementById('vsetko').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajmensieho').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajvecsieho').style.display = 'none'; document.getElementById('podlaPohlavia').style.display = 'block'; document.getElementById('podlaStatnejPrislusnosti').style.display = 'none';">
</input>
<input type="button" class="tlacitko" value="Zoraď podµa počtu rokov hore" onclick="javascript:document.getElementById('vsetko').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajmensieho').style.display = 'block'; document.getElementById('podlaPoctuRokovOdNajvecsieho').style.display = 'none'; document.getElementById('podlaPohlavia').style.display = 'none'; document.getElementById('podlaStatnejPrislusnosti').style.display = 'none';">
</input>
<input type="button" class="tlacitko" value="Zoraď podµa počtu rokov dole" onclick="javascript:document.getElementById('vsetko').style.display = 'none';document.getElementById('podlaPoctuRokovOdNajmensieho').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajvecsieho').style.display = 'block'; document.getElementById('podlaPohlavia').style.display = 'none'; document.getElementById('podlaStatnejPrislusnosti').style.display = 'none';">
</input>
<input type="button" class="tlacitko" value="Zoraď podµa ątátnej prísluąnosti" onclick="javascript:document.getElementById('vsetko').style.display = 'none';document.getElementById('podlaPoctuRokovOdNajmensieho').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajvecsieho').style.display = 'none'; document.getElementById('podlaPohlavia').style.display = 'none'; document.getElementById('podlaStatnejPrislusnosti').style.display = 'block';">
</input>
<input type="button" class="tlacitko" value="Vytlači»" onclick="javascript:window.location.href='filmyVsetky.pdf';">
</input>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
从这个源代码中我为您修剪了无用的数据。我只需要一种方法来做到这一点。请记住:选择一行并将数据导出为 PDF 后,不会将所有表格导出为 PDF。
谢谢。
Ok. Here is my situation. I've got XML file with data and XSLT with format data. I know that i need propably XSL-FO to convert to PDF format. But i need after select one row with the data about person to convert them in to pdf propably through XSL-FO.
Here is my code
<?xml version="1.0" encoding="iso-8859-2" ?>
<?xml-stylesheet type="text/xsl" href="pacienti.xsl"?>
<pacienti>
<pacient>
<id>1</id>
<meno>Jozef</meno>
<priezvisko>Hubáč</priezvisko>
<pohlavie>M</pohlavie>
<DN-den>1</DN-den>
<DN-mesiac>1</DN-mesiac>
<DN-rok>1991</DN-rok>
<pocetRokov>20</pocetRokov>
<adresa>Lipová 20, Banská Bystrica</adresa>
<statnaPrislusnost>SK</statnaPrislusnost>
<rodneCislo>910101/1234</rodneCislo>
<zdravotnaPoistovna>25</zdravotnaPoistovna>
<diagnoza>E120</diagnoza>
</pacient>
<pacient>
<id>2</id>
<meno>Peter</meno>
<priezvisko>Imrią</priezvisko>
<pohlavie>M</pohlavie>
<DN-den>5</DN-den>
<DN-mesiac>2</DN-mesiac>
<DN-rok>1990</DN-rok>
<pocetRokov>21</pocetRokov>
<adresa>Pietrová 333, Banská ©tiavnica</adresa>
<statnaPrislusnost>SK</statnaPrislusnost>
<rodneCislo>900205/5658</rodneCislo>
<zdravotnaPoistovna>21</zdravotnaPoistovna>
<diagnoza>A23</diagnoza>
</pacient>
</pacienti>
and here is XSLT code
<body onload="javascript:document.getElementById('vsetko').style.display = 'block'; document.getElementById('podlaPoctuRokovOdNajmensieho').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajvecsieho').style.display = 'none'; document.getElementById('podlaPohlavia').style.display = 'none'; document.getElementById('podlaStatnejPrislusnosti').style.display = 'none';">
<div id="vsetko" style="position:relative; top:70px;">
<h2>Databáza pacientov (zoradená podµa ID)</h2>
<table border="2" id="zvyraznene" width="100%">
<tr class="tabulcicka" >
<th bgcolor="yellow">Id:</th>
<th>Priezvisko, meno:</th>
<th>Dátum narodenia:</th>
<th>Pohlavie</th>
<th>©tátna prísluąnos»</th>
<th>Adresa</th>
<th>Rodné číslo</th>
<th>Zdravotná pois»ovňa</th>
<th>Diagnóza</th>
</tr>
<xsl:for-each select="pacienti/pacient">
<xsl:sort select="id" data-type="number">
</xsl:sort>
<tr onmouseover="this.className='zvyraznene'" onmouseout="this.className='normalne'">
<td>
<xsl:value-of select="id">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="priezvisko">
</xsl:value-of>,<xsl:value-of select="meno">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="DN-den">
</xsl:value-of>.<xsl:value-of select="DN-mesiac">
</xsl:value-of>.<xsl:value-of select="DN-rok">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="pohlavie">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="statnaPrislusnost">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="adresa">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="rodneCislo">
</xsl:value-of>
</td>
<td>
<xsl:value-of select="zdravotnaPoistovna">
</xsl:value-of>
</td>
<td align="center" >
<xsl:value-of select="diagnoza">
</xsl:value-of>
</td>
</tr>
</xsl:for-each>
</table>
</div>
<div id="menu">
<input type="button" class="tlacitko" value="Vąetci pacienti" onclick="javascript:document.getElementById('vsetko').style.display = 'block'; document.getElementById('podlaPoctuRokovOdNajmensieho').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajvecsieho').style.display = 'none'; document.getElementById('podlaPohlavia').style.display = 'none'; document.getElementById('podlaStatnejPrislusnosti').style.display = 'none';">
</input>
<input type="button" class="tlacitko" value="Zoraď podµa pohlavia" onclick="javascript:document.getElementById('vsetko').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajmensieho').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajvecsieho').style.display = 'none'; document.getElementById('podlaPohlavia').style.display = 'block'; document.getElementById('podlaStatnejPrislusnosti').style.display = 'none';">
</input>
<input type="button" class="tlacitko" value="Zoraď podµa počtu rokov hore" onclick="javascript:document.getElementById('vsetko').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajmensieho').style.display = 'block'; document.getElementById('podlaPoctuRokovOdNajvecsieho').style.display = 'none'; document.getElementById('podlaPohlavia').style.display = 'none'; document.getElementById('podlaStatnejPrislusnosti').style.display = 'none';">
</input>
<input type="button" class="tlacitko" value="Zoraď podµa počtu rokov dole" onclick="javascript:document.getElementById('vsetko').style.display = 'none';document.getElementById('podlaPoctuRokovOdNajmensieho').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajvecsieho').style.display = 'block'; document.getElementById('podlaPohlavia').style.display = 'none'; document.getElementById('podlaStatnejPrislusnosti').style.display = 'none';">
</input>
<input type="button" class="tlacitko" value="Zoraď podµa ątátnej prísluąnosti" onclick="javascript:document.getElementById('vsetko').style.display = 'none';document.getElementById('podlaPoctuRokovOdNajmensieho').style.display = 'none'; document.getElementById('podlaPoctuRokovOdNajvecsieho').style.display = 'none'; document.getElementById('podlaPohlavia').style.display = 'none'; document.getElementById('podlaStatnejPrislusnosti').style.display = 'block';">
</input>
<input type="button" class="tlacitko" value="Vytlači»" onclick="javascript:window.location.href='filmyVsetky.pdf';">
</input>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
From this source code I am trim the useless data for you. I just need the way to do that. Remember: After select one row with data export to PDF, no all table export to PDF.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XSLT 的结果是创建一个 resultTree(或一组 resultNode)。将其提交给 XSL-FO 并没有什么神奇之处。如果 XSLT 的结果是一组不相交的节点,则确保存在包含它们作为结果树(文档)的根节点。
然后我建议两种策略:
The result of XSLT is to create a resultTree (or a set of resultNodes). There is no magic to submit this to XSL-FO. If the result of XSLT is a set of disjoint nodes, then make sure there is a root node containing them as a resultTree (document).
I then suggest two strategies: