2010-07-21 171 views
4

我轉換一些XML數據放入文檔中的格式「的Excel XML電子表格2003」XML - XSLT轉換 - 生成特殊的「<? ... ?>」標籤

這一切工作正常,但我有一個問題生成結果文件的正確標題。 應該基本上是形式:

<?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"> 

<!-- end of header here and the transformation data goes below --> 

<Workbook> 

XSLT文件是

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" media-type="text/xml"/> 
    <xsl:template match="/"> 
<?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"> 

但結果文件的<?mso-application progid="Excel.Sheet"?>行丟失。

我明白<? ...?>是一個特殊的標籤 - 這樣可問題是,怎麼能由XSLT產生

感謝

+0

你使用什麼編程語言?如果是php,請嘗試禁用php.ini中的short_tags – Sarfraz 2010-07-21 14:37:03

+0

@sAc - 感謝評論,我不是php,我一直在尋找一般的xsl方法,而Alejandro提供了我正在尋找的答案 – kristof 2010-07-21 15:04:02

回答

12

與任一輸入,這個樣式表:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" media-type="text/xml"/> 
    <xsl:template match="/"> 
     <xsl:processing-instruction name="mso-application">progid="Excel.Sheet"</xsl:processing-instruction> 
     <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:template> 
</xsl:stylesheet> 

結果:

<?xml version="1.0" encoding="utf-8"?> 
<?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" /> 
+0

感謝Alejandro,我沒有想法什麼xsl:標籤名稱尋找 – kristof 2010-07-21 14:55:43

+0

@kristof:你很好!在http://www.w3.org/TR/xslt中學習XSLT規範也是一件好事 – 2010-07-21 15:28:57