How to create work sheets dynamically using XSLT?

2019-09-12 04:09发布

I want to create the worksheets dynamically based on dataset results (all data set results are same output format)returned by procedure.

XML :

<NewDataset>
<Table>
 <record>
 <id>1</id>
 <name>sdf</name>
<record>
<record>
<id>2</id>
 <name>sdfooop</name>
</record>
</Table>
<Table1>
<record>
 <id>1</id>
 <name>sdffff</name>
<record>
<record>
<id>2</id>
 <name>sdfwerwerwe</name>
</record>
</Table1>

In above example stored procedure returning 2 result sets Table,Table1.(This results set count may vary ).Please tell me how to dynamically create worksheets in same workbook using XSLT .

Thanks in advance..

1条回答
等我变得足够好
2楼-- · 2019-09-12 04:39

Roughly:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/NewDataset">
    <Workbook>
        <xsl:for-each select="*[starts-with(name(), 'Table')]">
            <Worksheet>
                <xsl:for-each select="record">
                    <Row>
                        <xsl:for-each select="*">
                            <Cell>
                                <xsl:value-of select="." />
                            </Cell>
                        </xsl:for-each>
                    </Row>
                </xsl:for-each>
            </Worksheet>
        </xsl:for-each>
    </Workbook>
</xsl:template>

</xsl:stylesheet>
查看更多
登录 后发表回答