xslfotransform.xsl 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: CCS
  5. (c) Copyright IBM Corp. 2005, 2010
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. -->
  8. <xsl:stylesheet version="1.0" xmlns:ldx="http://developer.cognos.com/schemas/rds/contentmodel/1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
  9. <xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" version="1.0"/>
  10. <xsl:variable name="gateway">http://localhost:80/cognos8/cgi-bin/cognos.cgi/</xsl:variable>
  11. <xsl:template match="/">
  12. <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  13. <fo:layout-master-set>
  14. <fo:simple-page-master page-height="11in" page-width="8.5in"
  15. margin="5mm 25mm 5mm 25mm" master-name="A4">
  16. <fo:region-body margin="20mm 0mm 20mm 0mm"/>
  17. </fo:simple-page-master>
  18. </fo:layout-master-set>
  19. <fo:page-sequence master-reference="A4">
  20. <fo:flow flow-name="xsl-region-body">
  21. <fo:block>
  22. <xsl:apply-templates select="//ldx:document/ldx:page"/>
  23. <xsl:apply-templates select="//ldx:filterResultSet/ldx:filterResult/ldx:reportElement/*"/>
  24. </fo:block>
  25. </fo:flow>
  26. </fo:page-sequence>
  27. </fo:root>
  28. </xsl:template>
  29. <xsl:template match="ldx:page">
  30. <fo:block-container overflow="hidden">
  31. <xsl:attribute name="id"><xsl:value-of select="ldx:id"/></xsl:attribute>
  32. <fo:block>
  33. <xsl:apply-templates select="ldx:header/*"/>
  34. </fo:block>
  35. <fo:block>
  36. <xsl:apply-templates select="ldx:body/*"/>
  37. </fo:block>
  38. <fo:block>
  39. <xsl:apply-templates select="ldx:footer/*"/>
  40. </fo:block>
  41. </fo:block-container>
  42. </xsl:template>
  43. <xsl:template match="ldx:item">
  44. <xsl:for-each select="*">
  45. <xsl:call-template name="item"/>
  46. </xsl:for-each>
  47. </xsl:template>
  48. <xsl:template name="item">
  49. <xsl:variable name="bookmark" select="ldx:drills/ldx:drill/ldx:bookmark"/>
  50. <xsl:choose>
  51. <xsl:when test="$bookmark">
  52. <fo:basic-link>
  53. <xsl:attribute name="internal-destination"><xsl:value-of select="$bookmark"/></xsl:attribute>
  54. <xsl:apply-templates select="."/>
  55. </fo:basic-link>
  56. </xsl:when>
  57. <xsl:otherwise>
  58. <xsl:apply-templates select="."/>
  59. </xsl:otherwise>
  60. </xsl:choose>
  61. </xsl:template>
  62. <xsl:template match="ldx:txt">
  63. <xsl:variable name="txtClass">
  64. <xsl:value-of select="ldx:style"/>
  65. </xsl:variable>
  66. <fo:inline>
  67. <xsl:for-each select="/ldx:document/ldx:styleGroup[ldx:name=$txtClass]">
  68. <xsl:apply-templates select="*"/>
  69. </xsl:for-each>
  70. <xsl:for-each select="/ldx:filterResultSet/ldx:styleGroup[ldx:name=$txtClass]">
  71. <xsl:apply-templates select="*"/>
  72. </xsl:for-each>
  73. <xsl:attribute name="id"><xsl:value-of select="ldx:id"/></xsl:attribute>
  74. <xsl:choose>
  75. <xsl:when test="ldx:fmtVal">
  76. <xsl:variable name="newText">
  77. <xsl:call-template name="replace-string">
  78. <xsl:with-param name="text" select="ldx:fmtVal"/>
  79. <xsl:with-param name="from" select="'('"/>
  80. <xsl:with-param name="to" select="' ('"/>
  81. </xsl:call-template>
  82. </xsl:variable>
  83. <xsl:value-of select="$newText"/>
  84. </xsl:when>
  85. <xsl:otherwise>
  86. <xsl:variable name="newText">
  87. <xsl:call-template name="replace-string">
  88. <xsl:with-param name="text" select="ldx:val"/>
  89. <xsl:with-param name="from" select="'('"/>
  90. <xsl:with-param name="to" select="'&#x200b;('"/>
  91. </xsl:call-template>
  92. </xsl:variable>
  93. <xsl:value-of select="$newText"/>
  94. </xsl:otherwise>
  95. </xsl:choose>
  96. </fo:inline>
  97. </xsl:template>
  98. <xsl:template name="replace-string">
  99. <xsl:param name="text"/>
  100. <xsl:param name="from"/>
  101. <xsl:param name="to"/>
  102. <xsl:choose>
  103. <xsl:when test="contains($text, $from)">
  104. <xsl:variable name="before" select="substring-before($text, $from)"/>
  105. <xsl:variable name="after" select="substring-after($text, $from)"/>
  106. <xsl:variable name="prefix" select="concat($before, $to)"/>
  107. <xsl:value-of select="$before"/>
  108. <xsl:value-of select="$to"/>
  109. <xsl:call-template name="replace-string">
  110. <xsl:with-param name="text" select="$after"/>
  111. <xsl:with-param name="from" select="$from"/>
  112. <xsl:with-param name="to" select="$to"/>
  113. </xsl:call-template>
  114. </xsl:when>
  115. <xsl:otherwise>
  116. <xsl:value-of select="$text"/>
  117. </xsl:otherwise>
  118. </xsl:choose>
  119. </xsl:template>
  120. <!-- <xsl:template name="textFormatter">
  121. <xsl:param name="breakText"/>
  122. <xsl:if test="string-length($breakText)">
  123. <xsl:value-of select="substring($breakText,1,3)"/>
  124. <xsl:call-template name="textFormatter">
  125. <xsl:with-param name="breakText" select="substring($breakText,4)"/>
  126. </xsl:call-template>
  127. </xsl:if>
  128. </xsl:template> -->
  129. <xsl:template match="ldx:img">
  130. <fo:inline>
  131. <fo:external-graphic>
  132. <xsl:attribute name="src">
  133. <xsl:if test="not(contains(ldx:url, 'http'))">
  134. <xsl:value-of select="$gateway"/>
  135. </xsl:if>
  136. <xsl:if test="substring(ldx:url,1,3)='../' or substring(ldx:url,1,3)='..\'"><xsl:text>..\</xsl:text></xsl:if>
  137. <xsl:value-of select="ldx:url"/>
  138. </xsl:attribute>
  139. </fo:external-graphic>
  140. </fo:inline>
  141. </xsl:template>
  142. <xsl:template match="ldx:cht">
  143. <fo:inline>
  144. <fo:external-graphic>
  145. <xsl:attribute name="id"><xsl:value-of select="ldx:id"/></xsl:attribute>
  146. <xsl:attribute name="src"><xsl:if test="not(contains(ldx:url, 'http'))"><xsl:value-of select="$gateway"/></xsl:if><xsl:value-of select="ldx:url"/>
  147. </xsl:attribute>
  148. </fo:external-graphic>
  149. </fo:inline>
  150. </xsl:template>
  151. <xsl:template match="ldx:html"/>
  152. <xsl:template match="ldx:hlink">
  153. <fo:basic-link>
  154. <xsl:attribute name="external-destination">
  155. <xsl:value-of select="ldx:target"/>
  156. </xsl:attribute>
  157. <xsl:apply-templates select="ldx:contents/*"/>
  158. </fo:basic-link>
  159. </xsl:template>
  160. <xsl:template match="ldx:bmrk">
  161. <fo:block>
  162. <xsl:attribute name="id"><xsl:value-of select="ldx:label"/></xsl:attribute>
  163. </fo:block>
  164. </xsl:template>
  165. <xsl:template match="ldx:rept">
  166. <xsl:variable name="reptClass">
  167. <xsl:value-of select="ldx:style"/>
  168. </xsl:variable>
  169. <fo:block>
  170. <xsl:for-each select="/ldx:document/ldx:styleGroup[ldx:name=$reptClass]">
  171. <xsl:apply-templates select="*"/>
  172. </xsl:for-each>
  173. <xsl:for-each select="/ldx:filterResultSet/ldx:styleGroup[ldx:name=$reptClass]">
  174. <xsl:apply-templates select="*"/>
  175. </xsl:for-each>
  176. <xsl:attribute name="id"><xsl:value-of select="ldx:id"/></xsl:attribute>
  177. <xsl:apply-templates select="ldx:item"/>
  178. </fo:block>
  179. </xsl:template>
  180. <xsl:template match="ldx:reptbl">
  181. <xsl:variable name="reptblClass">
  182. <xsl:value-of select="ldx:style"/>
  183. </xsl:variable>
  184. <fo:table fox:widow-content-limit="6 * 1.2em" table-layout="fixed" width="100%">
  185. <xsl:attribute name="padding">0</xsl:attribute>
  186. <xsl:attribute name="border">0</xsl:attribute>
  187. <xsl:attribute name="id"><xsl:value-of select="ldx:id"/></xsl:attribute>
  188. <xsl:attribute name="border-collapse">collapse</xsl:attribute>
  189. <xsl:for-each select="/ldx:document/ldx:styleGroup[ldx:name=$reptblClass]">
  190. <xsl:apply-templates select="*"/>
  191. </xsl:for-each>
  192. <xsl:for-each select="/ldx:filterResultSet/ldx:styleGroup[ldx:name=$reptblClass]">
  193. <xsl:apply-templates select="*"/>
  194. </xsl:for-each>
  195. <xsl:for-each select="ldx:row[0]/ldx:cell">
  196. <fo:table-column column-width="proportional-column-width(1)"/>
  197. </xsl:for-each>
  198. <fo:table-body>
  199. <xsl:for-each select="ldx:row">
  200. <fo:table-row>
  201. <xsl:apply-templates select="ldx:cell"/>
  202. </fo:table-row>
  203. </xsl:for-each>
  204. </fo:table-body>
  205. </fo:table>
  206. </xsl:template>
  207. <xsl:template match="ldx:rtxt">
  208. <xsl:call-template name="RichTextItem"/>
  209. </xsl:template>
  210. <xsl:template name="RichTextItem">
  211. <xsl:for-each select="ldx:item">
  212. <xsl:call-template name="RichTextItem"/>
  213. </xsl:for-each>
  214. <xsl:apply-templates select="ldx:div|ldx:span|ldx:txt|ldx:rtList"/>
  215. </xsl:template>
  216. <xsl:template match="ldx:div">
  217. <xsl:variable name="divClass">
  218. <xsl:value-of select="ldx:style"/>
  219. </xsl:variable>
  220. <fo:block>
  221. <xsl:for-each select="/ldx:document/ldx:styleGroup[ldx:name=$divClass]">
  222. <xsl:apply-templates select="*"/>
  223. </xsl:for-each>
  224. <xsl:for-each select="/ldx:filterResultSet/ldx:styleGroup[ldx:name=$divClass]">
  225. <xsl:apply-templates select="*"/>
  226. </xsl:for-each>
  227. <xsl:for-each select="ldx:item">
  228. <xsl:call-template name="RichTextItem"/>
  229. </xsl:for-each>
  230. </fo:block>
  231. </xsl:template>
  232. <xsl:template match="ldx:span">
  233. <xsl:variable name="spanClass">
  234. <xsl:value-of select="ldx:style"/>
  235. </xsl:variable>
  236. <fo:block>
  237. <fo:inline>
  238. <xsl:for-each select="/ldx:document/ldx:styleGroup[ldx:name=$spanClass]">
  239. <xsl:apply-templates select="*"/>
  240. </xsl:for-each>
  241. <xsl:for-each select="/ldx:filterResultSet/ldx:styleGroup[ldx:name=$spanClass]">
  242. <xsl:apply-templates select="*"/>
  243. </xsl:for-each>
  244. <xsl:for-each select="ldx:item">
  245. <xsl:call-template name="RichTextItem"/>
  246. </xsl:for-each>
  247. </fo:inline>
  248. </fo:block>
  249. </xsl:template>
  250. <xsl:template match="ldx:rtList">
  251. <xsl:variable name="rtListClass">
  252. <xsl:value-of select="ldx:style"/>
  253. </xsl:variable>
  254. <xsl:choose>
  255. <xsl:when test="ldx:ordered = 'true'">
  256. <fo:list-block provisional-distance-between-starts="1cm" provisional-label-separation="0.5">
  257. <xsl:attribute name="space-after">
  258. <xsl:choose>
  259. <xsl:when test="ancestor::ldx:rtList"><xsl:text>0pt</xsl:text></xsl:when>
  260. <xsl:otherwise><xsl:text>12pt</xsl:text></xsl:otherwise>
  261. </xsl:choose>
  262. </xsl:attribute>
  263. <xsl:attribute name="start-indent">
  264. <xsl:variable name="nested">
  265. <xsl:choose>
  266. <xsl:when test="count(ancestor::ldx:rtList)">
  267. <xsl:value-of select="1 + (count(ancestor::ldx:rtList)) * 1.25"/>
  268. </xsl:when>
  269. <xsl:otherwise><xsl:text>1</xsl:text></xsl:otherwise>
  270. </xsl:choose>
  271. </xsl:variable>
  272. <xsl:value-of select="concat($nested, 'cm')"/>
  273. </xsl:attribute>
  274. <xsl:for-each select="/ldx:document/ldx:styleGroup[ldx:name=$rtListClass]">
  275. <xsl:apply-templates select="*"/>
  276. </xsl:for-each>
  277. <xsl:for-each select="/ldx:filterResultSet/ldx:styleGroup[ldx:name=$rtListClass]">
  278. <xsl:apply-templates select="*"/>
  279. </xsl:for-each>
  280. <xsl:for-each select="ldx:listItem">
  281. <fo:list-item>
  282. <fo:list-item-label end-indent="label-end()">
  283. <fo:block>
  284. <xsl:variable name="label-num"><xsl:number value="position()"/></xsl:variable>
  285. <xsl:number value="$label-num" format="1. "/>
  286. </fo:block>
  287. </fo:list-item-label>
  288. <fo:list-item-body start-indent="body-start()">
  289. <fo:block>
  290. <xsl:call-template name="RichTextItem"/>
  291. </fo:block>
  292. </fo:list-item-body>
  293. </fo:list-item>
  294. </xsl:for-each>
  295. </fo:list-block>
  296. </xsl:when>
  297. <xsl:otherwise>
  298. <fo:list-block provisional-distance-between-starts="1cm" provisional-label-separation="0.5">
  299. <xsl:attribute name="space-after">
  300. <xsl:choose>
  301. <xsl:when test="ancestor::ldx:rtList"><xsl:text>0pt</xsl:text></xsl:when>
  302. <xsl:otherwise><xsl:text>12pt</xsl:text></xsl:otherwise>
  303. </xsl:choose>
  304. </xsl:attribute>
  305. <xsl:attribute name="start-indent">
  306. <xsl:variable name="nested">
  307. <xsl:choose>
  308. <xsl:when test="count(ancestor::ldx:rtList)">
  309. <xsl:value-of select="1 + (count(ancestor::ldx:rtList)) * 1.25"/>
  310. </xsl:when>
  311. <xsl:otherwise><xsl:text>1</xsl:text></xsl:otherwise>
  312. </xsl:choose>
  313. </xsl:variable>
  314. <xsl:value-of select="concat($nested, 'cm')"/>
  315. </xsl:attribute>
  316. <xsl:for-each select="/ldx:document/ldx:styleGroup[ldx:name=$rtListClass]">
  317. <xsl:apply-templates select="*"/>
  318. </xsl:for-each>
  319. <xsl:for-each select="/ldx:filterResultSet/ldx:styleGroup[ldx:name=$rtListClass]">
  320. <xsl:apply-templates select="*"/>
  321. </xsl:for-each>
  322. <xsl:for-each select="ldx:listItem">
  323. <fo:list-item>
  324. <fo:list-item-body start-indent="body-start()">
  325. <fo:block>
  326. <xsl:call-template name="RichTextItem"/>
  327. </fo:block>
  328. </fo:list-item-body>
  329. </fo:list-item>
  330. </xsl:for-each>
  331. </fo:list-block>
  332. </xsl:otherwise>
  333. </xsl:choose>
  334. </xsl:template>
  335. <xsl:template match="ldx:lcr">
  336. <xsl:apply-templates select="ldx:item"/>
  337. </xsl:template>
  338. <xsl:template match="ldx:lst">
  339. <xsl:variable name="lstClass">
  340. <xsl:value-of select="ldx:style"/>
  341. </xsl:variable>
  342. <fo:table fox:widow-content-limit="6 * 1.2em" table-layout="fixed" width="100%">
  343. <xsl:attribute name="padding">0</xsl:attribute>
  344. <xsl:attribute name="border">0</xsl:attribute>
  345. <xsl:attribute name="border-collapse">collapse</xsl:attribute>
  346. <xsl:for-each select="/ldx:document/ldx:styleGroup[ldx:name=$lstClass]">
  347. <xsl:apply-templates select="*"/>
  348. </xsl:for-each>
  349. <xsl:for-each select="/ldx:filterResultSet/ldx:styleGroup[ldx:name=$lstClass]">
  350. <xsl:apply-templates select="*"/>
  351. </xsl:for-each>
  352. <xsl:for-each select="ldx:colTitle">
  353. <xsl:call-template name="createColumns"/>
  354. </xsl:for-each>
  355. <fo:table-body>
  356. <xsl:if test="ldx:colTitle">
  357. <fo:table-row>
  358. <xsl:apply-templates select="ldx:colTitle"/>
  359. </fo:table-row>
  360. </xsl:if>
  361. <xsl:apply-templates select="ldx:group"/>
  362. </fo:table-body>
  363. </fo:table>
  364. </xsl:template>
  365. <xsl:template match="ldx:colTitle">
  366. <xsl:variable name="colTitleClass">
  367. <xsl:value-of select="ldx:style"/>
  368. </xsl:variable>
  369. <fo:table-cell>
  370. <xsl:for-each select="/ldx:document/ldx:styleGroup[ldx:name=$colTitleClass]">
  371. <xsl:apply-templates select="*"/>
  372. </xsl:for-each>
  373. <xsl:for-each select="/ldx:filterResultSet/ldx:styleGroup[ldx:name=$colTitleClass]">
  374. <xsl:apply-templates select="*"/>
  375. </xsl:for-each>
  376. <fo:block-container overflow="hidden">
  377. <fo:block>
  378. <xsl:apply-templates select="ldx:item"/>
  379. </fo:block>
  380. </fo:block-container>
  381. </fo:table-cell>
  382. </xsl:template>
  383. <xsl:template match="ldx:grp | ldx:group">
  384. <xsl:apply-templates select="*"/>
  385. </xsl:template>
  386. <xsl:template match="ldx:header | ldx:footer">
  387. <xsl:apply-templates select="ldx:row"/>
  388. </xsl:template>
  389. <xsl:template match="ldx:row">
  390. <fo:table-row>
  391. <xsl:apply-templates select="ldx:cell"/>
  392. </fo:table-row>
  393. </xsl:template>
  394. <xsl:template match="ldx:cell">
  395. <xsl:call-template name="cell"/>
  396. </xsl:template>
  397. <xsl:template match="ldx:ctab">
  398. <xsl:variable name="ctabClass">
  399. <xsl:value-of select="ldx:style"/>
  400. </xsl:variable>
  401. <fo:table fox:widow-content-limit="6 * 1.2em" table-layout="fixed" width="100%">
  402. <xsl:attribute name="padding">0</xsl:attribute>
  403. <xsl:attribute name="border">0</xsl:attribute>
  404. <xsl:attribute name="id"><xsl:value-of select="ldx:id"/></xsl:attribute>
  405. <xsl:attribute name="border-collapse">collapse</xsl:attribute>
  406. <xsl:for-each select="/ldx:document/ldx:styleGroup[ldx:name=$ctabClass]">
  407. <xsl:apply-templates select="*"/>
  408. </xsl:for-each>
  409. <xsl:for-each select="/ldx:filterResultSet/ldx:styleGroup[ldx:name=$ctabClass]">
  410. <xsl:apply-templates select="*"/>
  411. </xsl:for-each>
  412. <xsl:choose>
  413. <xsl:when test="ldx:row/ldx:nestedDimension/ldx:nestedDimension">
  414. <xsl:call-template name="createColumns"/>
  415. <xsl:call-template name="createColumns"/>
  416. <xsl:call-template name="createColumns"/>
  417. </xsl:when>
  418. <xsl:when test="ldx:row/ldx:nestedDimension">
  419. <xsl:call-template name="createColumns"/>
  420. <xsl:call-template name="createColumns"/>
  421. </xsl:when>
  422. <xsl:otherwise>
  423. <xsl:call-template name="createColumns"/>
  424. </xsl:otherwise>
  425. </xsl:choose>
  426. <xsl:for-each select="ldx:column">
  427. <xsl:call-template name="nestedColumns"/>
  428. </xsl:for-each>
  429. <fo:table-body>
  430. <fo:table-row>
  431. <xsl:apply-templates select="ldx:corner"/>
  432. <xsl:apply-templates select="ldx:column"/>
  433. </fo:table-row>
  434. <xsl:if test="count(ldx:column/ldx:nestedDimension) > 0">
  435. <fo:table-row>
  436. <xsl:call-template name="nestedTable"/>
  437. </fo:table-row>
  438. </xsl:if>
  439. <xsl:for-each select="ldx:row">
  440. <fo:table-row>
  441. <xsl:call-template name="insideNestedRowDimension"/>
  442. </fo:table-row>
  443. <xsl:if test="count(ldx:nestedDimension) > 1">
  444. <xsl:call-template name="otherInsideNestedRowDimension"/>
  445. </xsl:if>
  446. </xsl:for-each>
  447. </fo:table-body>
  448. </fo:table>
  449. </xsl:template>
  450. <xsl:template name="nestedColumns">
  451. <xsl:choose>
  452. <xsl:when test="ldx:nestedDimension">
  453. <xsl:for-each select="ldx:nestedDimension">
  454. <xsl:call-template name="nestedColumns"/>
  455. </xsl:for-each>
  456. </xsl:when>
  457. <xsl:otherwise>
  458. <xsl:call-template name="createColumns"/>
  459. </xsl:otherwise>
  460. </xsl:choose>
  461. </xsl:template>
  462. <xsl:template name="createColumns">
  463. <xsl:variable name="colWidth">
  464. <xsl:value-of select="ldx:style"/>
  465. </xsl:variable>
  466. <fo:table-column>
  467. <xsl:for-each select="/ldx:document/ldx:styleGroup[ldx:name=$colWidth]">
  468. <xsl:for-each select="ldx:boxStyle/ldx:width">
  469. <xsl:attribute name="column-width">
  470. 3 * <xsl:call-template name="processSizeValue"/>
  471. </xsl:attribute>
  472. </xsl:for-each>
  473. </xsl:for-each>
  474. <xsl:for-each select="/ldx:filterResultSet/ldx:styleGroup[ldx:name=$colWidth]">
  475. <xsl:for-each select="ldx:boxStyle/ldx:width">
  476. <xsl:attribute name="column-width">
  477. 3 * <xsl:call-template name="processSizeValue"/>
  478. </xsl:attribute>
  479. </xsl:for-each>
  480. </xsl:for-each>
  481. </fo:table-column>
  482. </xsl:template>
  483. <xsl:template match="ldx:corner">
  484. <xsl:call-template name="cell"/>
  485. </xsl:template>
  486. <xsl:template name="cell">
  487. <xsl:variable name="cellClass">
  488. <xsl:value-of select="ldx:style"/>
  489. </xsl:variable>
  490. <fo:table-cell>
  491. <xsl:for-each select="/ldx:document/ldx:styleGroup[ldx:name=$cellClass]">
  492. <xsl:apply-templates select="*"/>
  493. </xsl:for-each>
  494. <xsl:for-each select="/ldx:filterResultSet/ldx:styleGroup[ldx:name=$cellClass]">
  495. <xsl:apply-templates select="*"/>
  496. </xsl:for-each>
  497. <xsl:if test="ldx:rspan">
  498. <xsl:attribute name="number-rows-spanned"><xsl:value-of select="ldx:rspan"/></xsl:attribute>
  499. </xsl:if>
  500. <xsl:if test="ldx:cspan">
  501. <xsl:attribute name="number-columns-spanned"><xsl:value-of select="ldx:cspan"/></xsl:attribute>
  502. </xsl:if>
  503. <fo:block-container overflow="hidden">
  504. <fo:block>
  505. <xsl:apply-templates select="ldx:item"/>
  506. </fo:block>
  507. </fo:block-container>
  508. </fo:table-cell>
  509. </xsl:template>
  510. <xsl:template match="ldx:column">
  511. <xsl:call-template name="nestedDimension"/>
  512. </xsl:template>
  513. <xsl:template name="nestedDimension">
  514. <xsl:for-each select="ldx:name">
  515. <xsl:call-template name="cell"/>
  516. </xsl:for-each>
  517. </xsl:template>
  518. <xsl:template name="nestedTable">
  519. <xsl:for-each select="ldx:column/ldx:nestedDimension | ldx:nestedDimension/ldx:nestedDimension">
  520. <xsl:call-template name="nestedDimension"/>
  521. </xsl:for-each>
  522. </xsl:template>
  523. <xsl:template name="insideNestedRowDimension">
  524. <xsl:for-each select="ldx:name">
  525. <xsl:call-template name="cell"/>
  526. </xsl:for-each>
  527. <xsl:for-each select="ldx:nestedDimension">
  528. <xsl:if test="position()=1">
  529. <xsl:call-template name="insideNestedRowDimension"/>
  530. </xsl:if>
  531. </xsl:for-each>
  532. <xsl:if test="count(ldx:nestedDimension) = 0">
  533. <xsl:variable name="start" select="ldx:start"/>
  534. <xsl:for-each select="ancestor::ldx:ctab/ldx:table/ldx:row[(position()-1)=$start]/ldx:cell">
  535. <xsl:call-template name="cell"/>
  536. </xsl:for-each>
  537. </xsl:if>
  538. </xsl:template>
  539. <xsl:template name="otherInsideNestedRowDimension">
  540. <xsl:for-each select="ldx:nestedDimension">
  541. <xsl:if test="position()!=1">
  542. <fo:table-row>
  543. <xsl:for-each select="ldx:name">
  544. <xsl:call-template name="cell"/>
  545. </xsl:for-each>
  546. <xsl:call-template name="otherInsideNestedRowDimension"/>
  547. </fo:table-row>
  548. </xsl:if>
  549. </xsl:for-each>
  550. <xsl:if test="count(ldx:nestedDimension) = 0">
  551. <xsl:variable name="start" select="ldx:start"/>
  552. <xsl:for-each select="ancestor::ldx:ctab/ldx:table/ldx:row[(position()-1)=$start]/ldx:cell">
  553. <xsl:call-template name="cell"/>
  554. </xsl:for-each>
  555. </xsl:if>
  556. </xsl:template>
  557. <xsl:template match="ldx:font">
  558. <xsl:attribute name="font-family">
  559. <xsl:value-of select="ldx:family"/>
  560. </xsl:attribute>
  561. <xsl:attribute name="font-size">
  562. <xsl:for-each select="ldx:size">
  563. <xsl:call-template name="processSizeValue"/>
  564. </xsl:for-each>
  565. </xsl:attribute>
  566. <xsl:apply-templates select="ldx:fontStyle/*"/>
  567. </xsl:template>
  568. <xsl:template match="ldx:bold">
  569. <xsl:if test=". = 'true'">
  570. <xsl:attribute name="font-weight">bold</xsl:attribute>
  571. </xsl:if>
  572. </xsl:template>
  573. <xsl:template match="ldx:italics">
  574. <xsl:if test=". = 'true'">
  575. <xsl:attribute name="font-style">italic</xsl:attribute>
  576. </xsl:if>
  577. </xsl:template>
  578. <xsl:template match="ldx:underline">
  579. <xsl:if test=". = 'true'">
  580. <xsl:attribute name="text-decoration">underline</xsl:attribute>
  581. </xsl:if>
  582. </xsl:template>
  583. <xsl:template match="ldx:overline">
  584. <xsl:if test=". = 'true'">
  585. <xsl:attribute name="text-decoration">overline</xsl:attribute>
  586. </xsl:if>
  587. </xsl:template>
  588. <xsl:template match="ldx:strikethrough">
  589. <xsl:if test=". = 'true'">
  590. <xsl:attribute name="text-decoration">line-through</xsl:attribute>
  591. </xsl:if>
  592. </xsl:template>
  593. <xsl:template match="ldx:boxStyle">
  594. <xsl:apply-templates select="*"/>
  595. </xsl:template>
  596. <xsl:template match="ldx:height">
  597. <xsl:attribute name="height">
  598. <xsl:call-template name="processSizeValue"/>
  599. </xsl:attribute>
  600. </xsl:template>
  601. <xsl:template match="ldx:margin">
  602. <xsl:for-each select="ldx:top | ldx:left | ldx:right | ldx:bottom">
  603. <xsl:call-template name="processMarginSide"/>
  604. </xsl:for-each>
  605. </xsl:template>
  606. <xsl:template match="ldx:padding">
  607. <xsl:for-each select="ldx:top | ldx:left | ldx:right | ldx:bottom">
  608. <xsl:call-template name="processPaddingSide"/>
  609. </xsl:for-each>
  610. </xsl:template>
  611. <xsl:template match="ldx:border">
  612. <xsl:for-each select="ldx:top | ldx:left | ldx:right | ldx:bottom">
  613. <xsl:call-template name="processBorderSide"/>
  614. </xsl:for-each>
  615. </xsl:template>
  616. <xsl:template name="processBorderSide">
  617. <xsl:variable name="side" select="name()"/>
  618. <xsl:for-each select="ldx:width">
  619. <xsl:variable name="borderwidth">
  620. <xsl:value-of select="concat('border-',$side,'-width')"/>
  621. </xsl:variable>
  622. <xsl:attribute name="{$borderwidth}">
  623. <xsl:call-template name="processSizeValue"/>
  624. </xsl:attribute>
  625. </xsl:for-each>
  626. <xsl:for-each select="ldx:color">
  627. <xsl:variable name="bordercolor">
  628. <xsl:value-of select="concat('border-',$side,'-color')"/>
  629. </xsl:variable>
  630. <xsl:attribute name="{$bordercolor}">
  631. <xsl:text>#</xsl:text><xsl:call-template name="color"/>
  632. </xsl:attribute>
  633. </xsl:for-each>
  634. <xsl:for-each select="ldx:lineStyle">
  635. <xsl:variable name="borderstyle">
  636. <xsl:value-of select="concat('border-',$side,'-style')"/>
  637. </xsl:variable>
  638. <xsl:attribute name="{$borderstyle}">
  639. <xsl:value-of select="translate(.,
  640. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
  641. </xsl:attribute>
  642. </xsl:for-each>
  643. </xsl:template>
  644. <xsl:template name="processMarginSide">
  645. <xsl:variable name="marginside">
  646. <xsl:value-of select="concat('margin-',name())"/>
  647. </xsl:variable>
  648. <xsl:attribute name="{$marginside}">
  649. <xsl:call-template name="processSizeValue"/>
  650. </xsl:attribute>
  651. </xsl:template>
  652. <xsl:template name="processPaddingSide">
  653. <xsl:variable name="paddingside">
  654. <xsl:value-of select="concat('padding-',name())"/>
  655. </xsl:variable>
  656. <xsl:attribute name="{$paddingside}">
  657. <xsl:call-template name="processSizeValue"/>
  658. </xsl:attribute>
  659. </xsl:template>
  660. <xsl:template match="ldx:hAlign">
  661. <xsl:attribute name="text-align">
  662. <xsl:value-of select="translate(.,
  663. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
  664. </xsl:attribute>
  665. </xsl:template>
  666. <xsl:template match="ldx:vAlign">
  667. <xsl:attribute name="vertical-align">
  668. <xsl:value-of select="translate(.,
  669. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
  670. </xsl:attribute>
  671. </xsl:template>
  672. <xsl:template match="ldx:fgColor">
  673. <xsl:attribute name="color">
  674. <xsl:text>#</xsl:text><xsl:call-template name="color"/>
  675. </xsl:attribute>
  676. </xsl:template>
  677. <xsl:template match="ldx:bgColor">
  678. <xsl:attribute name="background-color">
  679. <xsl:text>#</xsl:text><xsl:call-template name="color"/>
  680. </xsl:attribute>
  681. </xsl:template>
  682. <xsl:template name="color">
  683. <xsl:call-template name="toHex">
  684. <xsl:with-param name="decimalNumber" select="ldx:Red"/>
  685. </xsl:call-template>
  686. <xsl:call-template name="toHex">
  687. <xsl:with-param name="decimalNumber" select="ldx:Green"/>
  688. </xsl:call-template>
  689. <xsl:call-template name="toHex">
  690. <xsl:with-param name="decimalNumber" select="ldx:Blue"/>
  691. </xsl:call-template>
  692. </xsl:template>
  693. <xsl:template name="processSizeValue">
  694. <xsl:value-of select="ldx:val"/>
  695. <xsl:call-template name="processUnits"/>
  696. </xsl:template>
  697. <xsl:template name="processUnits">
  698. <xsl:variable name="units" select="ldx:units"/>
  699. <xsl:choose>
  700. <xsl:when test="$units = 'PERCENT'">
  701. <xsl:text>%</xsl:text>
  702. </xsl:when>
  703. <xsl:otherwise>
  704. <xsl:value-of select="translate($units,
  705. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
  706. </xsl:otherwise>
  707. </xsl:choose>
  708. </xsl:template>
  709. <xsl:variable name="hexDigits" select="'0123456789ABCDEF'"/>
  710. <xsl:template name="toHex">
  711. <xsl:param name="decimalNumber"/>
  712. <xsl:if test="$decimalNumber &lt;= 16">
  713. <xsl:text>0</xsl:text>
  714. </xsl:if>
  715. <xsl:call-template name="toHexVal">
  716. <xsl:with-param name="decimalNumber" select="$decimalNumber"/>
  717. </xsl:call-template>
  718. </xsl:template>
  719. <xsl:template name="toHexVal">
  720. <xsl:param name="decimalNumber"/>
  721. <xsl:if test="$decimalNumber >= 16">
  722. <xsl:call-template name="toHexVal">
  723. <xsl:with-param name="decimalNumber" select="floor($decimalNumber div 16)"/>
  724. </xsl:call-template>
  725. </xsl:if>
  726. <xsl:value-of select="substring($hexDigits,
  727. ($decimalNumber mod 16) + 1, 1)"/>
  728. </xsl:template>
  729. <xsl:template match="*">
  730. <!--Unknown element. Ignore-->
  731. </xsl:template>
  732. </xsl:stylesheet>