Hallo,
Ich habe ein definiertes und nicht abänderbares Eingabeformat, das ich in ein Ausgabeformat umwandeln muss. Die Quelle ist ein Dataset, das ich aus einem Textfile ziehe, und das Ausgabeformat ist SpreadsheetML (XML-Format für Excel). Details darüber sind aber nicht so wichtig für diese Frage.
Das Format dieses Datasets ist folgendermassen (ein Beispiel):
Das Ausgangsfromat sieht so aus:
Bei Ausgangsformat gibt es also für jede Tabelle ein Tag, im Eingangsformat werden aber Tabellen und Rows sozusagen in einem Tag zusammengefasst.
Ich muss jetzt pro Tabelle ein Worksheet erstellen. Im Beispiel oben wären das 2 Worksheets. Das grösste Problem dabei ist, dass die Anzahl Tabellen variabel ist. Bis jetzt habe ich es "hardcodiert" für eine feste Anzahl Tabellen, schlussendlich muss es aber variabel sein.
Eingesetzt werden kann leider nur XSLT1.0, die Version 2.0 wird von meiner Entwicklungsumgebung (Visual Studio) noch nicht unterstützt.
Ich wäre sehr dankbar für Hilfe, weil ich jetzt nämlich schon einige Tage an dem Problem rumkaue und es einfach nicht schaffe.
PS: Hier noch mein aktueller XSLT-Code, falls meine Beschreibung noch nicht ganz klar ist:
Ich habe ein definiertes und nicht abänderbares Eingabeformat, das ich in ein Ausgabeformat umwandeln muss. Die Quelle ist ein Dataset, das ich aus einem Textfile ziehe, und das Ausgabeformat ist SpreadsheetML (XML-Format für Excel). Details darüber sind aber nicht so wichtig für diese Frage.
Das Format dieses Datasets ist folgendermassen (ein Beispiel):
HTML Code:
<dataset> <Table1> <col1>Wert a</col1> <col2>Wert b</col2> <col3>Wert c</col3> </Table1> <Table1> <col1>Wert d</col1> <col2>Wert e</col2> <col3>Wert f</col2> </Table1> <Table2> <col1>Wert g</col1> <col2>Wert h</col2> </Table2> </dataset>
HTML Code:
<Worksheet> <table> <row> <cell></cell> </row> </table> </Worksheet>
Ich muss jetzt pro Tabelle ein Worksheet erstellen. Im Beispiel oben wären das 2 Worksheets. Das grösste Problem dabei ist, dass die Anzahl Tabellen variabel ist. Bis jetzt habe ich es "hardcodiert" für eine feste Anzahl Tabellen, schlussendlich muss es aber variabel sein.
Eingesetzt werden kann leider nur XSLT1.0, die Version 2.0 wird von meiner Entwicklungsumgebung (Visual Studio) noch nicht unterstützt.
Ich wäre sehr dankbar für Hilfe, weil ich jetzt nämlich schon einige Tage an dem Problem rumkaue und es einfach nicht schaffe.
PS: Hier noch mein aktueller XSLT-Code, falls meine Beschreibung noch nicht ganz klar ist:
HTML Code:
<xsl:stylesheet version="1.0" xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> <xsl:template match="/"> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> <Styles> <Style ss:ID="s21"> <NumberFormat ss:Format="0"/> </Style> </Styles> <Worksheet ss:Name="Table"> <Table x:FullColumns="1" x:FullRows="1"> <Row> <xsl:for-each select="/*/Table[position() = 1]/*"> <Cell> <Data ss:Type="String"> <xsl:value-of select="local-name()"/> </Data> </Cell> </xsl:for-each> </Row> <xsl:apply-templates select="/*/Table"/> </Table> </Worksheet> <Worksheet ss:Name="Zusammenstellung"> <Table x:FullColumns="1" x:FullRows="1"> <Row> <xsl:for-each select="/*/Zusammenstellung[position() = 1]/*"> <Cell> <Data ss:Type="String"> <xsl:value-of select="local-name()"/> </Data> </Cell> </xsl:for-each> </Row> <xsl:apply-templates select="/*/Zusammenstellung"/> </Table> </Worksheet> </Workbook> </xsl:template> <xsl:template match="/*/*"> <Row> <xsl:apply-templates/> </Row> </xsl:template> <xsl:template match="GESICHERTEGB"> <Cell ss:StyleID="s21"> <Data ss:Type="Number"> <xsl:value-of select="."/> </Data> </Cell> </xsl:template> <xsl:template match="MASTERSERVER | SICHERUNGSTYP | F7 | HALTEFRIST | JOBID | F15 | F16 | F17 | F18 | F19 | Haltezeit | SummeMonat"> <Cell> <Data ss:Type="Number"> <xsl:value-of select="."/> </Data> </Cell> </xsl:template> <xsl:template match="STARTSICHERUNG | ENDESICHERUNG | MASTERSERVER |SICHERUNGSTYP | NETBACKUPCLIENT | SICHERUNGSART | MEDIASERVER | POLICY | SCHEDULE | LAUFWERK"> <Cell> <Data ss:Type="String"> <xsl:value-of select="."/> </Data> </Cell> </xsl:template> </xsl:stylesheet>
Comment