AntennaHouse / pdf5-ml

Antenna House PDF5-ML DITA-OT Plug-in
23 stars 9 forks source link

Can <?PubTbl?> be used to render table? #249

Closed ChhunE closed 3 months ago

ChhunE commented 3 months ago

Hello, I have table as below with PubTbl. I found that it is been use in Arbortext formatter (PTC).

<table>
  <tgroup cols="2">
    <colspec colname="col1" colwidth="50mm" />
    <colspec colname="col2" colwidth="50mm" />
    <tbody>
      <row>
        <entry><?PubTbl cell border-bottom-style="none" border-left-style="none" border-top-style="none"?>
          <p>Column 1</p>
        </entry>
        <entry><?PubTbl cell border-bottom-style="none" border-right-style="none" border-top-style="none"?>
          <p>Column 2</p>
        </entry>
      </row>
    </tbody>
  </tgroup>
</table>

I want to apply it border-bottom-style='none' border-left-style='none' border-top-style='none' into table cell. Is there any way possible to handle this within table template? Any comment or sample is appriciated. Thank you.

ToshihikoMakita commented 3 months ago

Are the PI contents written with XSL-FO defined properties?

ToshihikoMakita commented 3 months ago

Rough sample code:

input.xml

<?xml version="1.0" encoding="UTF-8"?>
<entry><?PubTbl cell border-bottom-style="none" border-left-style="none" border-top-style="none"?>
    <p>Column 1</p>
</entry>

test.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:math="http://www.w3.org/2005/xpath-functions/math"
    xmlns:ahf="http://www.antennahouse.com/names/XSLT/Functions/Document"
    exclude-result-prefixes="xs math"
    version="3.0">

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="entry">
        <xsl:variable name="pi" as="node()*" select="processing-instruction()[1]"/>
        <fo:table-cell>
            <xsl:copy-of select="$pi => ahf:pubTblPiToProp()"/>
            <!-- Cell contents: Only a sample -->
            <xsl:value-of select="p => string()"/>
        </fo:table-cell>        
    </xsl:template>

    <xsl:function name="ahf:pubTblPiToProp" as="attribute()*">
        <xsl:param name="prmPi" as="processing-instruction()"/>
        <xsl:choose>
            <xsl:when test="$prmPi => name() eq 'PubTbl'">
                <xsl:variable name="foPropDesc" as="xs:string" select="$prmPi => string() => substring-after('cell ')"/>
                <xsl:variable name="foPropDescs" as="xs:string*" select="$foPropDesc => tokenize('\s')"/>
                <xsl:for-each select="$foPropDescs">
                    <xsl:variable name="foPropDef" as="xs:string" select="."/>
                    <xsl:variable name="propName" as="xs:string" select="$foPropDef => substring-before('=')"/>
                    <xsl:variable name="propValue" as="xs:string" select="$foPropDef => substring-after('=&quot;') => substring-before('&quot;')"/>
                    <xsl:attribute name="{$propName}" select="$propValue"/>
                </xsl:for-each>
            </xsl:when>
            <xsl:otherwise>
                <xsl:sequence select="()"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:function>
</xsl:stylesheet>

output.xml

<?xml version="1.0" encoding="UTF-8"?>
<fo:table-cell xmlns:ahf="http://www.antennahouse.com/names/XSLT/Functions/Document"
               xmlns:fo="http://www.w3.org/1999/XSL/Format"
               border-bottom-style="none"
               border-left-style="none"
               border-top-style="none">Column 1</fo:table-cell>
ChhunE commented 3 months ago

The issue solved. Your sample is really help a lot. Thank you so much.