XML中用于生成pdf的SVG元素

XML中用于生成pdf的SVG元素,xml,pdf,xslt,svg,apache-fop,Xml,Pdf,Xslt,Svg,Apache Fop,我有以下xsl: <fo:block space-before="5mm" font-size="12pt" display-align="center" text-align="center"> <fo:instream-foreign-object background-color="white" content-height="200mm" content-width="150mm" height="200mm" width="150mm

我有以下xsl:

<fo:block space-before="5mm" font-size="12pt" display-align="center" text-align="center">

                <fo:instream-foreign-object background-color="white" content-height="200mm" content-width="150mm" height="200mm" width="150mm" padding="5pt">
                        <svg width="15cm" height="20cm" version="1.1" viewBox="0 0 300 300" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg">


                            <xsl:variable name="var_span">
                                <xsl:value-of select="pdftest/span" />
                            </xsl:variable>
                            <xsl:variable name="var_width2Balken">
                                <xsl:value-of select="pdftest/width2Balken" />
                            </xsl:variable>
                            <xsl:variable name="var_xoffset">
                                <xsl:value-of select="pdftest/xoffset" />
                            </xsl:variable>
                            <xsl:variable name="var_yoffset">
                                <xsl:value-of select="pdftest/yoffset" />
                            </xsl:variable>
                            <xsl:variable name="var_yMax">
                                <xsl:value-of select="pdftest/yMax" />
                            </xsl:variable>
                            <xsl:variable name="var_yMin">
                                <xsl:value-of select="pdftest/yMin" />
                            </xsl:variable>
                            <xsl:variable name="var_xMax">
                                <xsl:value-of select="pdftest/xMax" />
                            </xsl:variable>

                            <!-- <xsl:variable name="var_xLast"> <xsl:value-of select="0" /> </xsl:variable> -->




                            <!-- <line x1="{$var_xoffset}" y1="{$var_yoffset -100}" x2="{$var_xMax}" y2="{$var_yoffset -100}" style="stroke:gray;stroke-width:1;" /> -->


                            <line x1="{$var_xoffset}" y1="{$var_yoffset}" x2="{$var_xMax + $var_xoffset}" y2="{$var_yoffset}" style="stroke:black;stroke-width:5;" />
                            <line x1="{$var_xoffset}" y1="0" x2="{$var_xoffset}" y2="{$var_yMin + $var_yMax}" style="stroke:black;stroke-width:5;" />





                        </svg>
                    </fo:instream-foreign-object>

                    </fo:block>
以及以下XML:

<pdftest>
    <span>10</span>
    <width2Balken>38</width2Balken>
    <xoffset>0</xoffset>
    <yoffset>280</yoffset>
    <xMax>300</xMax>
    <yMax>200</yMax>
    <yMin>100</yMin>
</pdftest>
我知道它在使用fop1.1生成pdf时运行良好

然而,我的问题是:是否可以将xml中的所有内容都放在xsl部分和xml部分,然后在xsl中只显示一个标记,而不显示所有逻辑等等

所以最终你会

XSL: <xsl:value-of select="svg-all"> 
在XML中,您的

<svg-all>all of the above xsl with the xml values</svg-all>
我知道这不是最好的编程,在xsl中包含所有controll元素更好,但我想知道这是否可能,以及如何实现。 任何帮助都会很好

谢谢。流浪汉

您只需要使用xsl:copy of,而不是xsl:value of

假设您有这样的XML

<pdftest>
    <span>10</span>
    <width2Balken>38</width2Balken>
    <xoffset>0</xoffset>
    <yoffset>280</yoffset>
    <xMax>300</xMax>
    <yMax>200</yMax>
    <yMin>100</yMin>
    <svg-all xmlns="http://www.w3.org/2000/svg">
        <line x1="0" y1="280" x2="300" y2="280" style="stroke:black;stroke-width:5;" />
        <line x1="0" y1="0" x2="0" y2="300" style="stroke:black;stroke-width:5;" />
    </svg-all>    
</pdftest>
注意,您需要在XSLT中声明svg名称空间

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
     xmlns:svg="http://www.w3.org/2000/svg">
你可以这样写

<xsl:variable name="var_span" select="pdftest/span" />

例如,您是说希望看到XML内部,还是只希望看到预先计算的值,如?谢谢。第二个是预先计算好的。但都在XML文件中
<xsl:variable name="var_span">
    <xsl:value-of select="pdftest/span" />
</xsl:variable>
<xsl:variable name="var_span" select="pdftest/span" />
<xsl:template match="/">
    <fo:block space-before="5mm" font-size="12pt" display-align="center" text-align="center">
        <fo:instream-foreign-object background-color="white" content-height="200mm" content-width="150mm" height="200mm" width="150mm" padding="5pt">
            <xsl:apply-templates select="pdftest" mode="svg" />
        </fo:instream-foreign-object>
    </fo:block>
</xsl:template>

<xsl:template match="pdftest" mode="svg">
    <svg width="15cm" height="20cm" version="1.1" viewBox="0 0 300 300" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg">
        <line x1="{xoffset}" y1="{yoffset}" x2="{xMax + xoffset}" y2="{yoffset}" style="stroke:black;stroke-width:5;" />
        <line x1="{xoffset}" y1="0" x2="{xoffset}" y2="{yMin + yMax}" style="stroke:black;stroke-width:5;" />
    </svg>
</xsl:template>