通过 XSLT 转换从 HTML 到 XML FlowDocument



我正在尝试像这样转换一个简单的 xhtml 文档:

<div>
<p>
<span>....</span>
</p>
<p>
<span>.... </span> 
</p>
<p>
<span>I am content </span>        
</p>
</div>

到像这样的流文档:

<?xml version="1.0" encoding="utf-16"?>
<FlowDocument PagePadding="5,0,5,0" xml:lang="de-de" AllowDrop="True" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib">
<FlowDocument.Resources>
</FlowDocument.Resources>
<Paragraph>.....</Paragraph>
<Paragraph>.....</Paragraph>
<Paragraph>I am Content</Paragraph>
</FlowDocument>

以下是我通过 xslt 转换 html 的可悲尝试:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:xhtml="http://www.idpf.org/2007/opf" version="2.0">
<xsl:output method="xml" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:template match="xhtml:span">
<xsl:copy>
<x:Paragraph>
<xsl:apply-templates select="@*|node()"/>
</x:Paragraph>
</xsl:copy>
</xsl:template>
</xsl:transform>

它目前无法创建段落,我对 XSLT 一无所知。请求帮助...请!!

好的,我找到了解决方案:

<xsl:template match="/">
<x:FlowDocument>
<xsl:apply-templates select="node() | @*" />
</x:FlowDocument>
</xsl:template>
<xsl:template match="p">
<x:Paragraph>
<xsl:apply-templates select="@*|node()"/>
</x:Paragraph>
</xsl:template>

最新更新