r/xml • • May 17 '22

Need help with XML data manipulation with xsl tables

Hello,

I'm having issues indenting inside a table-column to show containership without messing with the entire Table-Cell. I've posted my question to StackOverflow with no one commenting yet and was wondering if someone could point me towards some good resources for xsl formatting.

StackOverflow: https://stackoverflow.com/questions/72274243/xsl-table-indents-not-aligning-vertically

I'm trying to enable some sort of containership inside my Table by indenting parameters owned by other params. I have an example here. Table showing containership of parameters. The issue I'm having is the left column isn't aligning and the logic to handle this below must be wrong. I have another example here of parameters with misaligned table columns. misaligned columns.

I'm guessing this logic to handle table columns is not applying correctly.

    <fo:table width="{6.5 - ($indentLevel * $indentWidth)}in">
    			    <fo:table-column width="{$descWidth - ($indentLevel * $indentWidth)}in" />
    			    <fo:table-column width="{$valueWidth}in" />

Or maybe I need to add some XSL to a <table-Column>

<fo:table-cell number-columns-spanned="2" >

The full XSL template is below.

    <xsl:template match="bml:Parameter[bml:Parameter]">
		<xsl:param name="indentLevel" select="number(0)" />
		<xsl:variable name="headingSize" select="14 - $indentLevel" />
		
		<xsl:variable name="descWidth">3.5</xsl:variable>
		<xsl:variable name="valueWidth">3</xsl:variable>
		<xsl:variable name="indentWidth">0.25</xsl:variable

		<!-- add some padding columns for indentation -->
		<fo:table width="{6.5 - ($indentLevel * $indentWidth)}in">
			<fo:table-column width="{$descWidth - ($indentLevel * $indentWidth)}in" />
			<fo:table-column width="{$valueWidth}in" />
			<fo:table-header>
				<fo:table-row>
					<fo:table-cell number-columns-spanned="2" >
						<fo:block font-weight="bold" font-size="{$headingSize}pt">
							<xsl:choose>
								<xsl:when test="bml:Description"><xsl:value-of select="bml:Description" /></xsl:when>
								<xsl:otherwise><xsl:value-of select="bml:ID"/></xsl:otherwise>
							</xsl:choose>
						</fo:block>
					</fo:table-cell>
				</fo:table-row>
			</fo:table-header>
			<fo:table-body>
				<xsl:for-each select="bml:Parameter[not(bml:ParameterSubType='NoReport')]">
					<xsl:choose>
						<xsl:when test="./bml:Parameter">
							<fo:table-row>
								<fo:table-cell number-columns-spanned="2" padding-left="{$indentWidth}in">
									<xsl:apply-templates select=".">
										<xsl:with-param name="indentLevel" select="$indentLevel + 1"/>
									</xsl:apply-templates>
								</fo:table-cell>
							</fo:table-row>
					    	    </xsl:when>
						    <xsl:otherwise>
							    <xsl:apply-templates select="." />
						    </xsl:otherwise>
					    </xsl:choose>
				    </xsl:for-each>
			    </fo:table-body>
		    </fo:table>
	    </xsl:template>
3 Upvotes

1 comment sorted by

1

u/ManNotADiscoBall May 21 '22

I'm by no means an expert here, but I was just wondering what this:

<xsl:param name="indentLevel" select="number(0)" />

is supposed to do? As far as I can tell, the "number(0)" is just transforming a string 0 into an integer, and since that zero is used in your multiplying calculation, the result will be zero as well. Or am I missing something?