我已经写好一个xsl,但是格式不对,我要保留空格。但是界面上没反应;请大家指出错误<?xml version="1.0" encoding="gb2312" ?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
><xsl:template match="/"><html>
<body><TABLE border="1" cellspacing="0" align = "left" frame= "border">
<xsl:for-each select="//ss:Workbook/ss:Worksheet/ss:Table/ss:Row "><tr>
<xsl:for-each select="ss:Cell">
<td><xsl:value-of select="ss:Data" /></td>
</xsl:for-each>
</tr>
</xsl:for-each></TABLE>
</body>
</html>
</xsl:template>
</xsl:transform>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
><xsl:template match="/"><html>
<body><TABLE border="1" cellspacing="0" align = "left" frame= "border">
<xsl:for-each select="//ss:Workbook/ss:Worksheet/ss:Table/ss:Row "><tr>
<xsl:for-each select="ss:Cell">
<td><xsl:value-of select="ss:Data" /></td>
</xsl:for-each>
</tr>
</xsl:for-each></TABLE>
</body>
</html>
</xsl:template>
</xsl:transform>
<games>
<game name=”XML Invaders” genre=”shooter”>
<description> Keep the invaders from building a well formed document</description>
<cds>1</cds>
<memory-cards>1</memory-cards>
</game>
<game name=”A Node in the XPath” genre=”rpg”>
<description>Find the missing node</description>
<cds>4</cds>
<memory-cards>2</memory-cards>
</game>
<game name=”XPath Racers” genre=”racing”>
<description>Race at breakneck speeds. Watch out for random predicates that seek to reduce your node set</description>
<cds>1</cds>
<memory-cards>1</memory-cards>
</game>
</games>
将这个xml转为html,先编写样式表,如下:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr><td>Name</td><td>Genre</td><td># Cd</td><td>Memory Cards</td></tr>
<xsl:for-each select="games/game">
<tr>
<td><xsl:value-of select="@name"/></td>
<td><xsl:value-of select="@genre"/></td>
<td><xsl:value-of select="./cds"/></td>
<td><xsl:value-of select="./memory-cards"/></td>
<td><xsl:value-of select=?/description?></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>转换的代码:
import org.xml.sax.SAXException;
import org.apache.xalan.xslt.XSLTProcessorFactory;
import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.XSLTResultTarget;
import org.apache.xalan.xslt.XSLTProcessor;
import java.io.FileOutputStream;
public class xalantransform{
public static void main(String[] args)
throws java.io.IOException,
java.net.MalformedURLException,
org.xml.sax.SAXException
{
XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
processor.process(new XSLTInputSource(args[0]),
new XSLTInputSource(args[1]),
new XSLTResultTarget(new FileOutputStream(args{2])));
}
}
空格怕是要 代替
<td><pre><xsl:value-of select="@genre"/></pre></td>
<td><pre><xsl:value-of select="./cds"/></pre></td>
<td><pre><xsl:value-of select="./memory-cards"/></pre></td>
<td><pre><xsl:value-of select=?/description?></pre></td>你的另一个帖子已经回答过了.
<?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">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Author>特别工作室</Author>
<LastAuthor>特别工作室</LastAuthor>
<Created>2006-03-27T09:02:51Z</Created>
<Company>华天科技</Company>
<Version>11.5606</Version>
</DocumentProperties>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>12945</WindowHeight>
<WindowWidth>16035</WindowWidth>
<WindowTopX>0</WindowTopX>
<WindowTopY>105</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Center"/>
<Borders/>
<Font ss:FontName="宋体" x:CharSet="134" ss:Size="12"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s21" ss:Name="常规_Sheet1">
<Alignment ss:Vertical="Center"/>
<Borders/>
<Font ss:FontName="宋体" x:CharSet="134"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s22" ss:Parent="s21">
<Alignment ss:Horizontal="Distributed" ss:Vertical="Center"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
</Borders>
<Font ss:FontName="宋体" x:CharSet="134" ss:Size="12" ss:Color="#000000"/>
<Interior ss:Color="#FFFFFF" ss:Pattern="Solid"/>
</Style>
<Style ss:ID="s23" ss:Parent="s21">
<Alignment ss:Vertical="Bottom"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
</Borders>
<Font ss:FontName="宋体" x:CharSet="134" ss:Size="12" ss:Color="#000000"/>
<Interior ss:Color="#FFFFFF" ss:Pattern="Solid"/>
</Style>
<Style ss:ID="s25">
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
</Borders>
</Style>
<Style ss:ID="s35">
<Borders/>
</Style>
<Style ss:ID="s36">
<Alignment ss:Vertical="Center"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
</Borders>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table ss:ExpandedColumnCount="4" ss:ExpandedRowCount="5" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="14.25">
<Column ss:AutoFitWidth="0" ss:Width="117.75"/>
<Column ss:Index="3" ss:AutoFitWidth="0" ss:Width="190.5"/>
<Row>
<Cell ss:StyleID="s22"><Data ss:Type="String">总 帐</Data></Cell>
<Cell ss:StyleID="s22"><Data ss:Type="String">科 目</Data></Cell>
<Cell ss:StyleID="s22"><Data ss:Type="String">单 位</Data></Cell>
<Cell ss:StyleID="s35"/>
</Row>
<Row>
<Cell ss:StyleID="s23"><Data ss:Type="String">财政零余额账户存款</Data></Cell>
<Cell ss:MergeDown="1" ss:StyleID="s36"><Data ss:Type="String">其他支出</Data></Cell>
<Cell ss:StyleID="s23"><Data ss:Type="String">0014北京市教育委员会</Data></Cell>
<Cell ss:StyleID="s35"/>
</Row>
<Row>
<Cell ss:StyleID="s25"/>
<Cell ss:Index="3" ss:StyleID="s23"><Data ss:Type="String"> 014305北京市校办产业管理中心</Data></Cell>
<Cell ss:StyleID="s35"/>
</Row>
<Row>
<Cell ss:StyleID="s23"><Data ss:Type="String">预拨经费</Data></Cell>
<Cell ss:StyleID="s23"><Data ss:Type="String">教育支出</Data></Cell>
<Cell ss:StyleID="s23"><Data ss:Type="String"> 014213北京工商大学</Data></Cell>
<Cell ss:StyleID="s35"/>
</Row>
<Row>
<Cell ss:StyleID="s35"/>
<Cell ss:StyleID="s35"/>
<Cell ss:StyleID="s35"/>
<Cell ss:StyleID="s35"/>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>2</ActiveRow>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet></Workbook>其他支出,就是合并单元格的。怎么才能正确显示呢?如果解决今天就结贴
不过我不知道你是不是要这样合并的?
但应该就是这种写法,如果要列合并,把rowspan 改成colspan即可,后边的2是合并的格数. <xsl:choose>
<xsl:when test="@ss:MergeDown = 1">
<xsl:attribute name="rowspan">
<xsl:value-of select="2"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
我把这段代码加了没反映啊!!!
这句话就是判断ss:MergeDown是不是等于1,在excel的xml文件中,MergeDown是表示向下合并一个单元格.如果我没猜错的话,向右合并一格应该是MergeRight="1"
<xsl:choose>
<xsl:when>
相当于switch语句,判断ss:MergeDown用的.
你把你的xslt文件贴出来,我帮你查查,我这边是没问题的.
是在你第一次贴出来文件的基础上改的<?xml version="1.0" encoding="gb2312" ?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
><xsl:template match="/"><html>
<body><TABLE border="1" cellspacing="0" align = "left" frame= "border">
<xsl:for-each select="//ss:Workbook/ss:Worksheet/ss:Table/ss:Row "><tr>
<xsl:for-each select="ss:Cell">
<td>
<xsl:choose>
<xsl:when test="@ss:MergeDown = 1">
<xsl:attribute name="rowspan">
<xsl:value-of select="2"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose> <pre>
<xsl:value-of select="@ss:MergeDown"/>
<xsl:value-of select="ss:Data"/>
</pre></td>
</xsl:for-each>
</tr>
</xsl:for-each></TABLE>
</body>
</html>
</xsl:template>
</xsl:transform>