|
|
从网上看到的从docx到html的基本转换
链接:
http://openxmldeveloper.org/archive/2006/06/30/333.aspx
xsl文件:
<?xml version="1.0" encoding="UTF-8" ?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> <xsl:output method="html" /> <xsl:template match="/"> <xsl:apply-templates select="//w:body" /> </xsl:template> <xsl:template match="w:body"> <html> <head /> <body> <pre> <xsl:apply-templates /> </pre> </body> </html> </xsl:template> <xsl:template match="w:p"> <div> <xsl:apply-templates select="w:r" /> </div> </xsl:template> <xsl:template match="w:r"> <xsl:apply-templates select="w:t" /> </xsl:template> <xsl:template match="w:t"> <span> <xsl:apply-templates select="../w:rPr" /> <xsl:value-of select="." /> </span> </xsl:template> <xsl:template match="w:rPr"> <xsl:attribute name="style"> <xsl:apply-templates /> </xsl:attribute> </xsl:template> <xsl:template match="w:u">text-decoration:underline;</xsl:template> <xsl:template match="w:b">font-weight:bold;</xsl:template> <xsl:template match="w:i">font-style:italic;</xsl:template></xsl:stylesheet>
用于转换的xml文件
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:o12="http://schemas.microsoft.com/office/2004/7/core" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.microsoft.com/office/omml/2004/12/core" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/3/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/3/main"> <w:body> <w:p> <w:r w:rsidR="00AD4F4A"> <w:t xml:space="preserve">This is </w:t> </w:r> <w:r w:rsidR="00A35A66"> <w:t>simple</w:t> </w:r> <w:r w:rsidR="00AD4F4A"> <w:t xml:space="preserve"> text. It preserves both spaces and line </w:t> </w:r> <w:r w:rsidR="00AD4F4A" w:rsidRPr="007949A6"> <w:rPr> <w:b/> </w:rPr> <w:t>breaks</w:t> </w:r> <w:r w:rsidR="007949A6" w:rsidRPr="007949A6"> <w:rPr> <w:b/> </w:rPr> <w:t xml:space="preserve"> in </w:t> </w:r> <w:proofErr w:type="spellStart"/> <w:r w:rsidR="007949A6" w:rsidRPr="007949A6"> <w:rPr> <w:b/> </w:rPr> <w:t>bold</w:t> </w:r> <w:r w:rsidR="00AD4F4A"> <w:t>.This</w:t> </w:r> <w:proofErr w:type="spellEnd"/> <w:r w:rsidR="00AD4F4A"> <w:t xml:space="preserve"> is preformatted text. It preserves both spaces and line </w:t> </w:r> <w:r w:rsidR="00AD4F4A" w:rsidRPr="0054521E"> <w:rPr> <w:i/> </w:rPr> <w:t>breaks</w:t> </w:r> <w:r w:rsidR="007949A6"> <w:rPr> <w:i/> </w:rPr> <w:t xml:space="preserve"> in </w:t> </w:r> <w:proofErr w:type="spellStart"/> <w:r w:rsidR="007949A6"> <w:rPr> <w:i/> </w:rPr> <w:t>italics</w:t> </w:r> <w:r w:rsidR="00AD4F4A"> <w:t>.This</w:t> </w:r> <w:proofErr w:type="spellEnd"/> <w:r w:rsidR="00AD4F4A"> <w:t xml:space="preserve"> is </w:t> </w:r> <w:r w:rsidR="00A35A66"> <w:rPr> <w:b/> </w:rPr> <w:t xml:space="preserve">simple preformatted </w:t> </w:r> <w:r w:rsidR="00AD4F4A"> <w:t xml:space="preserve"> text. It preserves both spaces and line breaks.</w:t> </w:r> </w:p> <w:p/> <w:p> <w:pPr> <w:rPr> <w:b/> </w:rPr> </w:pPr> <w:r w:rsidR="00AD4F4A" w:rsidRPr="0054521E"> <w:rPr> <w:b/> </w:rPr> <w:t xml:space="preserve">New </w:t> </w:r> <w:r w:rsidR="0054521E" w:rsidRPr="0054521E"> <w:rPr> <w:b/> </w:rPr> <w:t>Heading</w:t> </w:r> <w:r w:rsidR="00AD4F4A" w:rsidRPr="0054521E"> <w:rPr> <w:b/> </w:rPr> <w:t>:</w:t> </w:r> </w:p> <w:p> <w:r w:rsidR="00AD4F4A"> <w:t xml:space="preserve">This is </w:t> </w:r> <w:r w:rsidR="007949A6"> <w:rPr> <w:u w:val="single"/> </w:rPr> <w:t>underlined</w:t> </w:r> <w:r w:rsidR="00AD4F4A"> <w:t xml:space="preserve"> text. It preserves both spaces and line breaks.</w:t> </w:r> </w:p> <w:p> <w:r w:rsidR="00AD4F4A"> <w:t>This is preformatted text. It preserves both spaces and line breaks.</w:t> </w:r> </w:p> <w:p/> <w:sectPr w:rsidR="00510025" w:rsidSect="00320151"> <w:pgSz w:w="12240" w:h="15840"/> <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/> <w:cols w:space="720"/> <w:docGrid w:linePitch="360"/> </w:sectPr> </w:body></w:document>
该页面上还提供了用C#转换xml的代码 |
|