从 XML 中的表中选择一些行后 + XSLT - 导出为 pdf

发布于 2024-12-16 22:14:01 字数 8737 浏览 0 评论 0原文

好的。这是我的情况。我有包含数据的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趁微风不噪 2024-12-23 22:14:01

XSLT 的结果是创建一个 resultTree(或一组 resultNode)。将其提交给 XSL-FO 并没有什么神奇之处。如果 XSLT 的结果是一组不相交的节点,则确保存在包含它们作为结果树(文档)的根节点。

然后我建议两种策略:

  • 将 resultTree 作为 XML 文档输出并将其序列化到文件 (rows.xml)。然后使用它作为 XSL-FO 的输入。如果您使用第三方工具
  • 集将输出树直接路由到 XSL-FO 的输入中,这可能是最简单的。这将取决于语言和包。例如,我使用 Java 并使用 FOP 作为第二个进程。我最近没有看过 FOP,但我确信它能够读取 InputStream。

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:

  • output the resultTree as an XML document and serialize it to file (rows.xml). Then use this as the input to XSL-FO. This may be the easiest if you are using a third party toolset
  • route the outputTree directly into the input of XSL-FO. This will be language and package dependent. For example I use Java and would use FOP as the second process. I haven't looked at FOP recently but I am sure it will be able to read an InputStream.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文