deus wrote:Can someone take a look for my xslt export file and tell me what i'm doing wrong?
I gave your XSLT filter a try. Your problem lies in the
processcol template. If your test
test="$currentCol < $totalCols" results in true, you call the
processcol template with the wrong number of parameters. This xslt filter at least processes repeating values without an error, although the tags are wrong:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
exclude-result-prefixes="office table text">
<xsl:output method="xml" indent="yes" encoding="UTF-8" omit-xml-declaration="no" standalone="yes"/>
<xsl:template match="/">
<xsl:for-each select="//table:table">
<xsl:if test="./table:table-row[2]">
<TABLE>
<xsl:attribute name="name"><xsl:value-of select="@table:name"/></xsl:attribute>
<xsl:apply-templates select="."/>
</TABLE>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="table:table">
<xsl:for-each select="table:table-row">
<xsl:call-template name="wiersze" />
</xsl:for-each>
</xsl:template>
<xsl:template name="wiersze">
<xsl:if test="position()>1">
<ROW>
<xsl:for-each select="table:table-cell">
<xsl:apply-templates select=".">
<xsl:with-param name="column"><xsl:number/></xsl:with-param>
</xsl:apply-templates>
</xsl:for-each>
</ROW>
</xsl:if>
</xsl:template>
<xsl:template match="table:table-cell">
<xsl:param name="column"/>
<xsl:choose>
<xsl:when test="@table:number-columns-repeated">
<xsl:variable name="numcols" select="number(@table:number-columns-repeated)"/>
<xsl:call-template name="processcol">
<xsl:with-param name="currentCol" select="0"/>
<xsl:with-param name="totalCols" select="$numcols"/>
<xsl:with-param name="tagName">
<xsl:for-each select="./../../table:table-row[1]/table:table-cell">
<xsl:if test="position() = $column">
<xsl:choose>
<xsl:when test="normalize-space(text:p) != ''">
<xsl:choose>
<xsl:when test="matches(normalize-space(text:p),'^[a-zA-Z]')">
<xsl:value-of select="text:p"/>
</xsl:when>
<xsl:otherwise>col_<xsl:value-of select="text:p"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>col_<xsl:value-of select="$column"/></xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</xsl:with-param>
<xsl:with-param name="tagContent">
<xsl:choose>
<xsl:when test="normalize-space(text:p) != ''">
<xsl:value-of select="text:p"/>
</xsl:when>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="komorki">
<xsl:with-param name="tagName">
<xsl:for-each select="./../../table:table-row[1]/table:table-cell">
<xsl:if test="position() = $column">
<xsl:choose>
<xsl:when test="normalize-space(text:p) != ''">
<xsl:choose>
<xsl:when test="matches(normalize-space(text:p),'^[a-zA-Z]')">
<xsl:value-of select="text:p"/>
</xsl:when>
<xsl:otherwise>col_<xsl:value-of select="text:p"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>col_<xsl:value-of select="$column"/></xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</xsl:with-param>
<xsl:with-param name="tagContent">
<xsl:choose>
<xsl:when test="normalize-space(text:p) != ''">
<xsl:value-of select="text:p"/>
</xsl:when>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="komorki">
<xsl:param name="tagName"/>
<xsl:param name="tagContent"/>
<xsl:element name="{$tagName}"><xsl:value-of select="$tagContent"/></xsl:element>
</xsl:template>
<xsl:template name="processcol">
<xsl:param name="currentCol"/>
<xsl:param name="totalCols"/>
<xsl:param name="tagName"/>
<xsl:param name="tagContent"/>
<xsl:choose>
<xsl:when test="$currentCol < $totalCols">
<xsl:element name="{$tagName}"><xsl:value-of select="$tagContent"/></xsl:element>
<xsl:call-template name="processcol">
<xsl:with-param name="currentCol" select="$currentCol + 1"/>
<xsl:with-param name="totalCols" select="$totalCols"/>
<xsl:with-param name="tagName" select="$tagName"/>
<xsl:with-param name="tagContent" select="$tagContent"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
The above xslt filter applied on:
Code: Select all
a b c d
1 2 3 4
5 6 7 8
9 9 9 9
10 10 11 11
12 12 12 13
14 15 15 15
results in this xml file:
Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TABLE name="Sheet1">
<ROW>
<a>1</a>
<b>2</b>
<c>3</c>
<d>4</d>
</ROW>
<ROW>
<a>5</a>
<b>6</b>
<c>7</c>
<d>8</d>
</ROW>
<ROW>
<a>9</a>
<a>9</a>
<a>9</a>
<a>9</a>
</ROW>
<ROW>
<a>10</a>
<a>10</a>
<b>11</b>
<b>11</b>
</ROW>
<ROW>
<a>12</a>
<a>12</a>
<a>12</a>
<b>13</b>
</ROW>
<ROW>
<a>14</a>
<b>15</b>
<b>15</b>
<b>15</b>
</ROW>
</TABLE>
Sorry, but I found no way how to fix the tag names, too.