XML 파일에서 PDF를 만들려고하고 있으며 XSL-FO/Apache FOP를 사용하여 지금까지 꽤 잘 작동하고 있습니다.XSL-FO/Apache FOP를 사용하여 테이블 행에서 동일한 템플릿을 반복하는 방법
XML 파일에는 기본적으로 바코드 정보가 들어 있습니다. 바코드 자체와 바코드 유형 (바코드 이미지를 추가합니다). 그래서
-----------------------
| barcode1 | barcode2 |
| codetype1 | codetype2 |
-----------------------
| barcode3 | barcode4 |
| codetype3 | codetype4 |
-----------------------
그리고 :
지금 내가 무엇을 출력으로보고 싶은 것은 이것이다.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
<xsl:template match="barcode-list">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simpleA4">
<fo:flow flow-name="xsl-region-body">
<fo:block font-size="10pt">
<fo:table table-layout="fixed" width="100%" border-collapse="separate">
<fo:table-column column-width="45%"/>
<fo:table-column column-width="45%"/>
<fo:table-body>
<xsl:apply-templates select="item"/>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="item">
<fo:table-row>
<fo:table-cell>
<fo:block wrap-option="wrap">
<xsl:value-of select="name"/>
</fo:block>
<fo:block wrap-option="wrap">
<xsl:value-of select="format"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
그래서 두 개의 열이 있고 난 그냥 셀에 채우기 위해 "항목"템플릿에서를 가리 수있는 가정 :
나는 다음과 같은 XSL을 정의했다.
이제 "항목"템플릿에 <table-row>
태그가 포함되어 있고 각 항목이 자체 테이블 행에 표시되는 것을 알게되었습니다. 그래서 내가 할 것은이있다 :
-----------------------
| barcode1 | |
| codetype1 | |
-----------------------
| barcode2 | |
| codetype2 | |
-----------------------
| barcode3 | |
| codetype3 | |
-----------------------
| barcode4 | |
| codetype4 | |
-----------------------
내 질문은 자신의 테이블 행의 각 항목을 얻는 것보다 원하는 출력을 얻을 수있는 XSL을 변경하는 방법은?
XSLT 1.1이었다 초안을 및 XSLT 2.0으로 대체되었다 지금/곧 XSLT 3.0. 어떤 XSLT 프로세서를 사용하고 있습니까? 또한 결과물의 모든 요소가'fo' 네임 스페이스에 있기 때문에'exclude-result-prefixes = "fo"'는 효과가 없습니다. 즉, XSLT 프로세서가 결과에 네임 스페이스를 포함해야합니다. 마지막으로'fo : root'에있는'xmlns : fo = "http://www.w3.org/1999/XSL/Format"은'xmlns : fo = "http : // www의 범위 내에 있습니다. .w3.org/1999/XSL/Format "을'xsl : stylesheet'에 추가합니다. 따라서 꼭 필요한 것은 아니며 결과에 영향을 미치지 않습니다. –
@TonyGraham 파일에서 두 요소 중 하나를 제거하면, Apache FOP는 언 바운드 요소와 알 수없는 태그에 대해 불평하는 예외를 throw합니다. – Baz
@TonyGraham XSLT 2.0을 준수하기 위해 문서를 변경해야하는 이유는 무엇입니까? – Baz