Convert Xslt to xsl-fo

I want to convert xslt to xsl-fo, but I'm not sure I can do this. I am trying to convert an XML list to an xsl-fo list. Can someone tell me where I can find that I have been doing Internet searches for a long time, there are not many examples of this. My XML is like that.

<p>TEXT</p> <ul> <li>Item1</li> <li>Item2</li> </ul> <p>ANOTHERTEXT</p> 

I am trying to use templates for this conversion, but my templates do not work to get xsl-fo. Can someone tell me if templates work in this conversion. If they work, can show me an example, I can not find anyone. My task is to get pdf whit fop

thanks


This is part of my XML document. I got some parts of the source code in HTML, and now I am changing the HTML to XML. I am trying to convert XML (whit list) to XSL-FO with XSLT. My problem is that I cannot come up with patterns for this conversion. My last task is to get a PDF file with FOP.

thanks

UPDATE

This is my XML:

 <Memoria> <name>TITLE</name> <Index>INDEX 2010</Index> <Seccion> <name>INFORMATION</name> <Contenido> <p>TEXT</p> <ul> <li>ITEM1</li> <li>ITEM2</li> </ul> <p>ANOTHER</p> </Contenido> </Seccion> </Memoria> 

I am testing your solution. Thank you all.

+6
source share
2 answers

If you are having problems with your templates not working, this could be a namespace problem. You should update the question with a more accurate example of your XML.

Here is an example.

XML input (fixed to be well formed)

 <root> <p>TEXT</p> <ul> <li>Item1</li> <li>Item2</li> </ul> <p>ANOTHERTEXT</p> </root> 

XSLT 1.0

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="/root"> <fo:root> <fo:layout-master-set> <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in"> <fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="my-page"> <fo:flow flow-name="xsl-region-body"> <xsl:apply-templates/> </fo:flow> </fo:page-sequence> </fo:root> </xsl:template> <xsl:template match="p"> <fo:block> <xsl:apply-templates/> </fo:block> </xsl:template> <xsl:template match="ul"> <fo:list-block padding="4pt"> <xsl:apply-templates/> </fo:list-block> </xsl:template> <xsl:template match="li"> <fo:list-item> <fo:list-item-label end-indent="label-end()"> <fo:block>&#x02022;</fo:block> </fo:list-item-label> <fo:list-item-body start-indent="body-start()"> <fo:block> <xsl:apply-templates/> </fo:block> </fo:list-item-body> </fo:list-item> </xsl:template> </xsl:stylesheet> 

XSL-FO Output

 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in"> <fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="my-page"> <fo:flow flow-name="xsl-region-body"> <fo:block>TEXT</fo:block> <fo:list-block padding="4pt"> <fo:list-item> <fo:list-item-label end-indent="label-end()"> <fo:block>β€’</fo:block> </fo:list-item-label> <fo:list-item-body start-indent="body-start()"> <fo:block>Item1</fo:block> </fo:list-item-body> </fo:list-item> <fo:list-item> <fo:list-item-label end-indent="label-end()"> <fo:block>β€’</fo:block> </fo:list-item-label> <fo:list-item-body start-indent="body-start()"> <fo:block>Item2</fo:block> </fo:list-item-body> </fo:list-item> </fo:list-block> <fo:block>ANOTHERTEXT</fo:block> </fo:flow> </fo:page-sequence> </fo:root> 

Apache FOP Output

enter image description here

+6
source

First make sure you have the xhtml file (no <br> etcetera). Then apply the xslt transform to create the fo file, then feed this so that fop and PDF appear.

Xslt fo style snippet:

  <xsl:template match="html:body"> <fo:page-sequence master-reference="all-pages"> <fo:title> <xsl:value-of select="/html:html/html:head/html:title"/> </fo:title> <fo:static-content flow-name="page-header"> <fo:block font-weight="bold" font-size="16pt" space-before.conditionality="retain" xsl:use-attribute-sets="page-header"><!-- space-before="{$page-header-margin}" --> <xsl:if test="$title-print-in-header = 'true'"> <xsl:value-of select="/html:html/html:head/html:title"/> </xsl:if> </fo:block> </fo:static-content> </fo:page-sequence> </xsl:template> 

Check http://www.w3schools.com/xslfo/default.asp for xslfo syntax.

See http://xmlgraphics.apache.org/fop/trunk/running.html for information on starting fop; loading fop.jar should be nearby.

Starting from vba, for example, as follows:

 Set shell = CreateObject("WScript.Shell") cmd = "java -Dfop.home=" & baseDir & " -cp " & baseDir & "build\fop.jar org.apache.fop.cli.Main -fo " & foName & " -pdf " & pdfName Call shell.Run(cmd, vbWindowFrame, True) 

(similar to command line)

0
source

Source: https://habr.com/ru/post/909356/


All Articles