通过Xslt转换到HTML FlowDocument的HTML

问题描述 投票:0回答:1

我正在尝试像这样转换一个简单的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一无所知。请求帮助...请!!

html xml xslt xhtml flowdocument
1个回答
0
投票

好,我找到了解决方法:

  <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>
© www.soinside.com 2019 - 2024. All rights reserved.