Ich verstehe nicht, warum einige Ausgabebereiche ihr style-Attribut auf eine leere Zeichenfolge festgelegt haben.Transform Oddity
Wie kann dies vereinfacht werden, um die Schleifen und Bedingungen zu entfernen?
Ich habe seit Tagen damit zu kämpfen. Ich schätze jede angebotene Hilfe. Ich weiß, dass der XLST weit vom Ideal entfernt ist. Ich lerne gerade.
XSLT
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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"
version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:for-each select="ss:Workbook/ss:Worksheet/ss:Table/ss:Row">
<xsl:element name="tr">
<xsl:for-each select="ss:Cell">
<xsl:element name="td">
<xsl:if test="not(ss:Data/*)"><xsl:value-of select="."/></xsl:if>
<xsl:for-each select="ss:Data/*">
<xsl:call-template name="recursive-template">
<xsl:with-param name="myElement" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:template>
<xsl:template name="recursive-template">
<xsl:param name="myElement" />
<xsl:if test="name($myElement)='Font'">
<xsl:element name="span">
<xsl:attribute name="style">
<xsl:if test="@html:Color">color:<xsl:value-of select="@html:Color"/>; </xsl:if>
<xsl:if test="@html:Size">font-size:<xsl:value-of select="@html:Size"/>pt; </xsl:if>
</xsl:attribute>
<xsl:choose>
<xsl:when test="$myElement/*">
<xsl:call-template name="recursive-template">
<xsl:with-param name="myElement" select="$myElement/*"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$myElement"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:if>
<xsl:if test="name($myElement)!='Font'">
<xsl:element name="{lower-case(name($myElement))}">
<xsl:choose>
<xsl:when test="$myElement/*">
<xsl:call-template name="recursive-template">
<xsl:with-param name="myElement" select="$myElement/*"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$myElement"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
OUTPUT
Der folgende Ausgang mit Ausnahme der wenigen Spannweiten mit leeren Stilattributen korrekt ist. Beachten Sie, dass das CSS inline sein muss, damit der HTML-Code per E-Mail gesendet werden kann und in Google Mail weiterhin korrekt angezeigt wird.
<tr>
<td>ID</td>
<td>Date</td>
<td>Quantity</td>
<td>Customer</td>
</tr>
<tr>
<td>754</td>
<td>2016-11-15T00:00:00.000</td>
<td>95</td>
<td><s><span style="">A</span></s><span style="color:#000000; ">jax</span></td>
</tr>
<tr>
<td>432</td>
<td>2016-11-03T00:00:00.000</td>
<td>14</td>
<td><span style="color:#000000; ">Kr</span><i><span style="">oo</span></i><span style="color:#000000; ">n</span></td>
</tr>
<tr>
<td>322</td>
<td>2016-11-01T00:00:00.000</td>
<td>52</td>
<td><b><s><span style="">S</span></s></b><span style="color:#000000; ">hou</span><span style="color:#FF0000; ">t</span><span style="color:#000000; ">er K</span><span style="color:#C65911; ">res</span><span style="color:#000000; ">t</span></td>
</tr>
XML
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<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="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s151">
<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2"/>
</Borders>
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"
ss:Bold="1"/>
</Style>
<Style ss:ID="s152">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom" ss:Indent="1"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2"/>
</Borders>
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"
ss:Bold="1"/>
</Style>
<Style ss:ID="s153">
<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
<Borders>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2"/>
</Borders>
</Style>
<Style ss:ID="s154">
<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
<Borders/>
<NumberFormat ss:Format="d\-mmm"/>
</Style>
<Style ss:ID="s155">
<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
<Borders/>
</Style>
<Style ss:ID="s156">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom" ss:Indent="1"/>
<Borders>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2"/>
</Borders>
</Style>
<Style ss:ID="s161">
<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2"/>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2"/>
</Borders>
</Style>
<Style ss:ID="s162">
<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2"/>
</Borders>
<NumberFormat ss:Format="d\-mmm"/>
</Style>
<Style ss:ID="s163">
<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2"/>
</Borders>
</Style>
<Style ss:ID="s164">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom" ss:Indent="1"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2"/>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
</Borders>
</Style>
<Style ss:ID="s165">
<Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
<Borders>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2"/>
</Borders>
<Interior ss:Color="#92D050" ss:Pattern="Solid"/>
</Style>
<Style ss:ID="s166">
<Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
<Borders/>
<Interior ss:Color="#92D050" ss:Pattern="Solid"/>
<NumberFormat ss:Format="d\-mmm"/>
</Style>
<Style ss:ID="s167">
<Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
<Borders/>
<Interior ss:Color="#92D050" ss:Pattern="Solid"/>
</Style>
<Style ss:ID="s170">
<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2"
ss:Color="#FF0000"/>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2"/>
</Borders>
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"
ss:Bold="1"/>
</Style>
<Style ss:ID="s185">
<Alignment ss:Horizontal="Right" ss:Vertical="Center" ss:Indent="2"/>
<Borders>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2"/>
</Borders>
<Interior ss:Color="#92D050" ss:Pattern="Solid"/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet4">
<Table ss:ExpandedColumnCount="4" ss:ExpandedRowCount="4"
ss:DefaultRowHeight="15">
<Column ss:AutoFitWidth="0" ss:Width="54.75"/>
<Column ss:AutoFitWidth="0" ss:Width="122.25"/>
<Column ss:AutoFitWidth="0" ss:Width="54.75"/>
<Column ss:AutoFitWidth="0" ss:Width="101.25"/>
<Row ss:Height="15.75">
<Cell ss:StyleID="s170"><Data ss:Type="String">ID</Data></Cell>
<Cell ss:StyleID="s151"><Data ss:Type="String">Date</Data></Cell>
<Cell ss:StyleID="s151"><Data ss:Type="String">Quantity</Data></Cell>
<Cell ss:StyleID="s152"><Data ss:Type="String">Customer</Data></Cell>
</Row>
<Row>
<Cell ss:StyleID="s153"><Data ss:Type="Number">754</Data></Cell>
<Cell ss:StyleID="s154"><Data ss:Type="DateTime">2016-11-15T00:00:00.000</Data></Cell>
<Cell ss:StyleID="s155"><Data ss:Type="Number">95</Data></Cell>
<Cell ss:StyleID="s156"><ss:Data ss:Type="String"
xmlns="http://www.w3.org/TR/REC-html40"><S><Font html:Color="#000000">A</Font></S><Font
html:Color="#000000">jax</Font></ss:Data></Cell>
</Row>
<Row ss:AutoFitHeight="0" ss:Height="27">
<Cell ss:StyleID="s165"><Data ss:Type="Number">432</Data></Cell>
<Cell ss:StyleID="s166"><Data ss:Type="DateTime">2016-11-03T00:00:00.000</Data></Cell>
<Cell ss:StyleID="s167"><Data ss:Type="Number">14</Data></Cell>
<Cell ss:StyleID="s185"><ss:Data ss:Type="String"
xmlns="http://www.w3.org/TR/REC-html40"><Font html:Color="#000000">Kr</Font><I><Font
html:Color="#000000">oo</Font></I><Font html:Color="#000000">n</Font></ss:Data></Cell>
</Row>
<Row ss:Height="19.5">
<Cell ss:StyleID="s161"><Data ss:Type="Number">322</Data></Cell>
<Cell ss:StyleID="s162"><Data ss:Type="DateTime">2016-11-01T00:00:00.000</Data></Cell>
<Cell ss:StyleID="s163"><Data ss:Type="Number">52</Data></Cell>
<Cell ss:StyleID="s164"><ss:Data ss:Type="String"
xmlns="http://www.w3.org/TR/REC-html40"><B><S><Font html:Size="14"
html:Color="#548235">S</Font></S></B><Font html:Color="#000000">hou</Font><Font
html:Color="#FF0000">t</Font><Font html:Color="#000000">er K</Font><Font
html:Color="#C65911">res</Font><Font html:Color="#000000">t</Font></ss:Data></Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
Danke viel, sendet diese mich in die richtige Richtung! –