2010-11-09 180 views
-2

我试图生成XSL一个excel文件出类拔萃,但xslo自动生成的xmlns名为模板节点的每一根元素属性: 在xsl:生成XSL问题

<?xml version="1.0"?> 
<?mso-application progid="Excel.Sheet"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       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:msxsl="urn:schemas-microsoft-com:xslt" 
       exclude-result-prefixes="msxsl"> 
    <xsl:output method="xml" indent="yes"/> 

    <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" > 
... 
     <xsl:call-template name="Styles"></xsl:call-template> 
    ... 
    </Workbook> 
    </xsl:template> 
    <xsl:template name ="Styles"> 
    <Styles > 
     <Style ss:ID="Default" ss:Name="Normal"> 
     <Alignment ss:Vertical="Bottom"/> 
     <Borders/> 
     <Font/> 
     <Interior/> 
     <NumberFormat/> 
     <Protection/> 
     </Style> 
     <Style ss:ID="m20452808"> 
     <Alignment ss:Vertical="Bottom" ss:WrapText="1"/> 
     <Borders> 
      <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" 
      ss:Color="#000000"/> 
      <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" 
      ss:Color="#000000"/> 
      <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" 
      ss:Color="#000000"/> 
     </Borders> 
     <Interior ss:Color="#FFFF00" ss:Pattern="Solid"/> 
     </Style> 
    </Styles> 
    </xsl:template> 

输出:

<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"> 
    <LastAuthor>Harold</LastAuthor> 
    <Created>2010-11-09T09:41:05Z</Created> 
    <LastSaved>2010-11-09T09:41:05Z</LastSaved> 
    <Version>11.5606</Version> 
    </DocumentProperties> 
    <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> 
    <WindowHeight>12780</WindowHeight> 
    <WindowWidth>18795</WindowWidth> 
    <WindowTopX>240</WindowTopX> 
    <WindowTopY>315</WindowTopY> 
    <ProtectStructure>False</ProtectStructure> 
    <ProtectWindows>False</ProtectWindows> 
    </ExcelWorkbook> 
<Styles xmlns=""> 

问题:

<Styles xmlns=""> 
..... 

任何想法?????

+0

什么?你如何试图从xsl生成一个excel文件?你如何得到这个输出?看来你想从Excel生成的xsl生成xml文件到我这里...你能清楚吗? – Shikiryu 2010-11-09 14:38:53

+0

我从xsl + xml生成xls – 2010-11-10 10:45:31

回答

2

问题:

<Styles xmlns="">

这是一个复位默认命名空间声明(在XML 1.1,你可以重置前缀的命名申报)。为什么?因为在Workbook文字结果元素中声明的默认名称空间传播到样式表中的下一个,但Styles不是样式表中的下一个,并且它位于空名称空间URI下。

解决方案:为样式表中的公共祖先声明所有文字结果元素的默认名称空间。好的做法是在xsl:stylesheet根元素中声明这一点。