最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

xslt - Image not displaying in PDF output - XSL:FO - Stack Overflow

programmeradmin1浏览0评论

I am working on the digitization of historical resources on the TEI Publisher platform. For the users will have the possibility to download this texts in xml format and also in pdf. But for the pdf output the image did not come out.

In the xml file, the image is encoded in this way:

<?xml-model href=".rng" type="application/xml" schematypens=".0"?><?xml-model href=".rng" type="application/xml"
    schematypens=";?>
<TEI xmlns=".0" xml:id="" rendition="tei:teisimple" xml:lang="es">
    <teiHeader xml:lang="en">
        <fileDesc>
            <titleStmt>
                <title></title>
                <author></author>
                <editor role="#scholarly"></editor>
                <editor role="#technical" xml:id="">r</editor>
                <editor role="#technical" xml:id=""></editor>
            </titleStmt>
            <editionStmt>
                <edition n="1.0.0">
                    <date type="digitizedEd" when="2023-06-22">2023-06-22</date>
                </edition>
            </editionStmt>
            <publicationStmt>
                <publisher xml:id="pubstmt-publisher">
                    <Name></Name>
                    <ref type="url" target=/</ref>
                </publisher>
                <distributor xml:id="pubstmt-distributor">
                    <Name></Name>
                    <ref type="url" target=""></ref>
                </distributor>
                <pubPlace role="digitizedEd" xml:id="pubstmt-pubplace">  </pubPlace>
                <availability xml:id="pubstmt-availability">
                    <licence target=".0" n="cc-by">
                        <p xml:id="p_ffjaztskfd">Creative
                                Commons Attribution 4.0 International (CC BY 4.0)</ref>.</p>
                    </licence>
                </availability>
                <date type="digitizedEd" when="2024-02-15">2024-02-15</date>
            </publicationStmt>
            <seriesStmt xml:id="seriesStmt">
                <title level="s"</title>
                <title level="j"></title>
                <editor xml:id="TD">
                    <persName ref="gnd:" full="yes">
                        <surname full="yes"></surname>, <forename full="yes"></forename>
                    </persName>
                </editor>
                <editor xml:id="MPMQ">
                    <persName>
                        <surname full="yes"></surname>, <forename full="yes">r</forename>
                    </persName>
                </editor>
            </seriesStmt>
            <sourceDesc>
                <p></p>
                <p> <ref source="">.</ref>
                </p>
            </sourceDesc>
        </fileDesc>
        <encodingDesc xml:lang="es">
            <classDecl>
                <taxonomy>
                    <desc></desc>
                    <category xml:id="">
                        <catDesc></catDesc>
                    </category>
                    <category>
                        <desc></desc>
                        <category xml:id="">
                            <catDesc></catDesc>
                        </category>
                        <category xml:id="">
                            <catDesc></catDesc>
                        </category>
                        <category xml:id="">
                            <catDesc></catDesc>
                        </category>
                        <category xml:id="">
                            <catDesc></catDesc>
                        </category>
                        <category xml:id="">
                            <catDesc></catDesc>
                        </category>
                    </category>
                </taxonomy>
            </classDecl>
        </encodingDesc>
        <profileDesc>
            <textClass>
                <catRef target=""/>
                <keywords scheme="palabras-clave" xml:lang="es">
                    <list>
                        <item></item>
                        <item></item>
                        <item></item>
                        <item></item>
                        <item></item>
                    </list>
                </keywords>
            </textClass>
        </profileDesc>
        <revisionDesc>
            <listChange>
                <change when="" who="">Initial Encoding<date></date>
                </change>
            </listChange>
        </revisionDesc>
    </teiHeader>
    <text>
        <front>
            <titlePage>
                <docTitle>
                    <titlePart><note n="*" place="end" xml:id="footnote-DCH"></note>
                    </titlePart>
                </docTitle>
                <docAuthor><note n="**" place="end" xml:id="footnote-author"/>
                </docAuthor>
            </titlePage>
        </front>
        <body>
            <div n="1">
                <head>1. Introducción</head>
                <p></p>
...
             <div n="6">
                <head>6. </head>
                <p> <term></term> .</p>
                        <graphic url="../dch/resources/images/palio_imagem.png"/>

the master.fo.xml that I wrote:

<fo:layout-master-set xmlns:xsl="; xmlns:fo=";>
    <fo:simple-page-master master-name="page-left" page-height="297mm" page-width="210mm" margin-bottom="10mm" margin-top="10mm" margin-left="36mm" margin-right="18mm">
        <fo:region-body margin-bottom="10mm" margin-top="16mm"/>
        <fo:region-before region-name="head-left" extent="10mm"/>
    </fo:simple-page-master>
    <fo:simple-page-master master-name="page-right" page-height="297mm" page-width="210mm" margin-bottom="10mm" margin-top="10mm" margin-left="18mm" margin-right="36mm">
        <fo:region-body margin-bottom="10mm" margin-top="16mm"/>
        <fo:region-before region-name="head-right" extent="10mm"/>
    </fo:simple-page-master>
    <fo:page-sequence-master master-name="page-content">
    <xsl:choose>
    <xsl:when test="graphic">
    <fo:external-graphic width="auto" height="auto" content-width="scale-to-fit" content-height="scale-to-fit" src="{$graphic}"/>
     </xsl:when>
      <xsl:otherwise>
      <fo:block>dont found it.</fo:block>
      </xsl:otherwise>
      </xsl:choose>
        <fo:repeatable-page-master-alternatives>
            <fo:conditional-page-master-reference master-reference="page-right" odd-or-even="odd"/>
            <fo:conditional-page-master-reference master-reference="page-left" odd-or-even="even"/>
        </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>
</fo:layout-master-set>

Can you have any idea why the image dont printed? Thanks a lot .
The repository from TEI Publisher is here:

I tried another "css media print" command, but I did not have success.

I am working on the digitization of historical resources on the TEI Publisher platform. For the users will have the possibility to download this texts in xml format and also in pdf. But for the pdf output the image did not come out.

In the xml file, the image is encoded in this way:

<?xml-model href="http://www.tei-c./release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng./ns/structure/1.0"?><?xml-model href="http://www.tei-c./release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml"
    schematypens="http://purl.oclc./dsdl/schematron"?>
<TEI xmlns="http://www.tei-c./ns/1.0" xml:id="" rendition="tei:teisimple" xml:lang="es">
    <teiHeader xml:lang="en">
        <fileDesc>
            <titleStmt>
                <title></title>
                <author></author>
                <editor role="#scholarly"></editor>
                <editor role="#technical" xml:id="">r</editor>
                <editor role="#technical" xml:id=""></editor>
            </titleStmt>
            <editionStmt>
                <edition n="1.0.0">
                    <date type="digitizedEd" when="2023-06-22">2023-06-22</date>
                </edition>
            </editionStmt>
            <publicationStmt>
                <publisher xml:id="pubstmt-publisher">
                    <Name></Name>
                    <ref type="url" target=/</ref>
                </publisher>
                <distributor xml:id="pubstmt-distributor">
                    <Name></Name>
                    <ref type="url" target=""></ref>
                </distributor>
                <pubPlace role="digitizedEd" xml:id="pubstmt-pubplace">  </pubPlace>
                <availability xml:id="pubstmt-availability">
                    <licence target="https://creativecommons./licenses/by/4.0" n="cc-by">
                        <p xml:id="p_ffjaztskfd">Creative
                                Commons Attribution 4.0 International (CC BY 4.0)</ref>.</p>
                    </licence>
                </availability>
                <date type="digitizedEd" when="2024-02-15">2024-02-15</date>
            </publicationStmt>
            <seriesStmt xml:id="seriesStmt">
                <title level="s"</title>
                <title level="j"></title>
                <editor xml:id="TD">
                    <persName ref="gnd:" full="yes">
                        <surname full="yes"></surname>, <forename full="yes"></forename>
                    </persName>
                </editor>
                <editor xml:id="MPMQ">
                    <persName>
                        <surname full="yes"></surname>, <forename full="yes">r</forename>
                    </persName>
                </editor>
            </seriesStmt>
            <sourceDesc>
                <p></p>
                <p> <ref source="">https://dch.hypotheses..</ref>
                </p>
            </sourceDesc>
        </fileDesc>
        <encodingDesc xml:lang="es">
            <classDecl>
                <taxonomy>
                    <desc></desc>
                    <category xml:id="">
                        <catDesc></catDesc>
                    </category>
                    <category>
                        <desc></desc>
                        <category xml:id="">
                            <catDesc></catDesc>
                        </category>
                        <category xml:id="">
                            <catDesc></catDesc>
                        </category>
                        <category xml:id="">
                            <catDesc></catDesc>
                        </category>
                        <category xml:id="">
                            <catDesc></catDesc>
                        </category>
                        <category xml:id="">
                            <catDesc></catDesc>
                        </category>
                    </category>
                </taxonomy>
            </classDecl>
        </encodingDesc>
        <profileDesc>
            <textClass>
                <catRef target=""/>
                <keywords scheme="palabras-clave" xml:lang="es">
                    <list>
                        <item></item>
                        <item></item>
                        <item></item>
                        <item></item>
                        <item></item>
                    </list>
                </keywords>
            </textClass>
        </profileDesc>
        <revisionDesc>
            <listChange>
                <change when="" who="">Initial Encoding<date></date>
                </change>
            </listChange>
        </revisionDesc>
    </teiHeader>
    <text>
        <front>
            <titlePage>
                <docTitle>
                    <titlePart><note n="*" place="end" xml:id="footnote-DCH"></note>
                    </titlePart>
                </docTitle>
                <docAuthor><note n="**" place="end" xml:id="footnote-author"/>
                </docAuthor>
            </titlePage>
        </front>
        <body>
            <div n="1">
                <head>1. Introducción</head>
                <p></p>
...
             <div n="6">
                <head>6. </head>
                <p> <term></term> .</p>
                        <graphic url="../dch/resources/images/palio_imagem.png"/>

the master.fo.xml that I wrote:

<fo:layout-master-set xmlns:xsl="http://www.w3./1999/XSL/Transform" xmlns:fo="http://www.w3./1999/XSL/Format">
    <fo:simple-page-master master-name="page-left" page-height="297mm" page-width="210mm" margin-bottom="10mm" margin-top="10mm" margin-left="36mm" margin-right="18mm">
        <fo:region-body margin-bottom="10mm" margin-top="16mm"/>
        <fo:region-before region-name="head-left" extent="10mm"/>
    </fo:simple-page-master>
    <fo:simple-page-master master-name="page-right" page-height="297mm" page-width="210mm" margin-bottom="10mm" margin-top="10mm" margin-left="18mm" margin-right="36mm">
        <fo:region-body margin-bottom="10mm" margin-top="16mm"/>
        <fo:region-before region-name="head-right" extent="10mm"/>
    </fo:simple-page-master>
    <fo:page-sequence-master master-name="page-content">
    <xsl:choose>
    <xsl:when test="graphic">
    <fo:external-graphic width="auto" height="auto" content-width="scale-to-fit" content-height="scale-to-fit" src="{$graphic}"/>
     </xsl:when>
      <xsl:otherwise>
      <fo:block>dont found it.</fo:block>
      </xsl:otherwise>
      </xsl:choose>
        <fo:repeatable-page-master-alternatives>
            <fo:conditional-page-master-reference master-reference="page-right" odd-or-even="odd"/>
            <fo:conditional-page-master-reference master-reference="page-left" odd-or-even="even"/>
        </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>
</fo:layout-master-set>

Can you have any idea why the image dont printed? Thanks a lot .
The repository from TEI Publisher is here: https://github/eeditiones/tei-publisher-app

I tried another "css media print" command, but I did not have success.

Share Improve this question edited Dec 10, 2024 at 7:42 lfurini 3,7884 gold badges34 silver badges50 bronze badges asked Nov 19, 2024 at 14:19 ndso86ndso86 111 silver badge2 bronze badges 2
  • is graphic in the top level of the input xml tree, is the xml tree free of namespaces? Then changing test="graphic" to test="graphic/@url" and src="{$graphic}" to src="graphic/@url" should do it, if the graphic url is like data:image/<supported type>;base64,... Otherwise we might need more information (larger context of the xml). It seems you are using the master.fo as xslt stylesheet. Also I am not sure if placing something in the layout-master-set will show it without being instantiated, can't check at the moment but soon experts will drop in – Stefan Hegny Commented Nov 21, 2024 at 14:45
  • Thank you for your comment. Unfortunately the changes did not work. To the question: no, the graphic is not in the top level of the input xml tree. And I do not know if graphic url is data:image/<supported type>;base64,... (What I have is ../resources/images/image.png") And this is the complete xml file. There are images in only 2 or 3 files. and this is an example. The <graphic url> is in the <div n="6">. (I dont know if you are familiar with TEI Publisher, but they say that PDF layout could be managed via ODD. I did, but it does not work for images) – ndso86 Commented Nov 26, 2024 at 9:50
Add a comment  | 

2 Answers 2

Reset to default 0

As @StefanHegny noted, the structure of your XSL-FO is not correct.

The diagram for the structure of an XSL-FO document from the XSL 1.1 Recommendation is:

The document element is fo:root. Some of the elements shown in the diagram are optional. Your content goes inside the fo:flow in an fo:page-sequence.

Additionally, fo:external-graphic is an inline FO, so it should be inside an fo:block element and not just a child of the fo:flow element.

You can find examples of XSL-FO usage in the Antenna House 'XSL-FO Samples Collection' at https://www.antennahouse/xsl-fo-samples. You can download the XSL-FO file for any sample to see how it was made.

thank you for your comments and advice. The problem was solved via ODD. Due to expired certifications, I had to put in the full path and that's how it worked

发布评论

评论列表(0)

  1. 暂无评论