|
Subject: Re: [xsl] How Can I Reference previous XML in Subsequent Iterations? From: Abel Braaksma <abel.online@xxxxxxxxx> Date: Wed, 18 Apr 2007 18:11:41 +0200 |
Cheers, -- Abel Braaksma
<xsl:stylesheet xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" exclude-result-prefixes="ss xsl">
<xsl:template match="/">
<xsl:apply-templates select="ss:Workbook/ss:Worksheet" />
</xsl:template> <xsl:template match="ss:Row">
<tr>
<xsl:apply-templates select="*" />
</tr>
</xsl:template> <xsl:template match="ss:Worksheet">
<table>
<xsl:apply-templates select="*"/>
</table>
</xsl:template> <xsl:template match="ss:Style">
<xsl:apply-templates select="*"/>
</xsl:template> <xsl:template match="ss:Alignment">
<!-- select attributes -->
<xsl:apply-templates select="@*" />
</xsl:template> <xsl:template match="@ss:Vertical">
<xsl:text>;vertical-align:</xsl:text>
<xsl:value-of select="."/>
</xsl:template> <xsl:template match="ss:Font">
<!-- select attributes -->
<xsl:apply-templates select="@*" />
</xsl:template> <xsl:template match="@ss:Underline">
<xsl:text>;text-decoration:</xsl:text>
<xsl:choose>
<xsl:when test=". = 'Single'">underline</xsl:when>
<xsl:otherwise>none</xsl:otherwise>
</xsl:choose>
</xsl:template>Here's a bit of an example of what I'm talking about. The original XML is several thousand lines long:
<?xml version="1.0"?>
<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:html="http://www.w3.org/TR/REC-html40"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<Styles>
<Style ss:ID="s30" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Verdana"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s33" ss:Name="Hyperlink">
<Font ss:FontName="Verdana" ss:Color="#0000D4" ss:Underline="Single"/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Row>
<Cell ss:Index="5" ss:StyleID="s30"><Data ss:Type="String">Some String</Data></Cell>
<Cell ss:Index="6" ss:StyleID="s30"><Data ss:Type="String">Some String 2</Data></Cell>
<Cell ss:Index="7" ss:StyleID="s33"><Data ss:Type="String">http://example.com</Data></Cell>
</Row>
</Worksheet>
</Workbook>
I'd like to convert this to:
<table>
<tr>
<td style="vertical-align:bottom;font-family:Verdana">Some String</td>
<td style="vertical-align:bottom;font-family:Verdana">Some String 2</td>
<td style="color:#0000D4;text-decoration:underline;font-family:Verdana"><a href="http://example.com">http://example.com</a></td>
</tr>
</table>
Chris Marshall
chris at getridofthiswholelongthingybecauseitstoconfusescrapers littlegreenviper dot com
http://www.cmarshall.net/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] How Can I Reference previ, David Carlisle | Thread | Re: [xsl] How Can I Reference previ, Abel Braaksma |
| Re: [xsl] How Can I Reference previ, David Carlisle | Date | Re: [xsl] How Can I Reference previ, Abel Braaksma |
| Month |