2010-11-09 85 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根元素中聲明這一點。