问题出在表单的基础数据结构中的number-columns-repeated属性到table:table-cell元素。详情请参阅http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=29674和http://user.services.openoffice.org/en/forum/viewtopic.php?f=9&t=11865。
虽然后面的链接声称已经解决了这个问题,但解决方案并不完全符合我的要求。我需要一个简单的基于索引的解决方案,它允许更灵活的xml代。这是我试图解决的问题。
我已经使用xslt 2.0来使用用户定义的函数。这里是样式表...
<xsl:output method="xml" indent="yes" encoding="UTF-8" omit-xml-declaration="no"/>
<xsl:function name="my:getColumnValue">
<xsl:param name="tableRow" as="node()"/>
<xsl:param name="colIndex"/>
<xsl:param name="currentIndex"/>
<xsl:choose>
<xsl:when test="$currentIndex < $colIndex">
<xsl:variable name="repeatColumns" select="$tableRow/table:table-cell[$currentIndex]/@table:number-columns-repeated"/>
<xsl:choose>
<xsl:when test="$repeatColumns">
<xsl:choose>
<xsl:when test="$currentIndex + $repeatColumns - 1 >= $colIndex"><xsl:value-of select="$tableRow/table:table-cell[$currentIndex]"/></xsl:when>
<xsl:otherwise><xsl:value-of select="my:getColumnValue($tableRow, $colIndex - $repeatColumns + 1, $currentIndex + 1)"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise><xsl:value-of select="my:getColumnValue($tableRow, $colIndex, $currentIndex + 1)"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$tableRow/table:table-cell[$colIndex]"/></xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:template match="//table:table">
<Tests>
<!-- Process all table rows -->
<xsl:variable name="colCount" select="count(table:table-row[1]/table:table-cell)"/>
<xsl:for-each select="table:table-row">
<xsl:if test="position() > 1">
<Test>
<SrNo><xsl:value-of select="my:getColumnValue(.,1,1)"/></SrNo>
<Name><xsl:value-of select="my:getColumnValue(.,2,1)"/></Name>
<Age><xsl:value-of select="my:getColumnValue(.,3,1)"/></Age>
<Height><xsl:value-of select="my:getColumnValue(.,4,1)"/></Height>
<Address><xsl:value-of select="my:getColumnValue(.,5,1)"/></Address>
</Test>
</xsl:if>
</xsl:for-each>
</Tests>
</xsl:template>
上面使用的标签是只是占位符。请用你的xslt中的适当的替换它们。该解决方案受到xslt处理器允许的递归调用次数的限制。
如果xslt 1.0支持以params的形式发送节点,那么我们可以尝试替换上述udf以获得基于模板的解决方案。如果你发现任何错误,请让我知道。
感谢您发布代码。如果你可以投我的答案,如果它是有用的,也将有所帮助:) – 2012-07-25 17:34:49