2008-11-07 21 views
10

Bazı Xaml'i .NET XslCompiledTransform kullanarak HTML'ye dönüştürmeye çalışıyorum ve xslt'i Xaml etiketleriyle eşleştirmek için zorluklarla karşılaşıyorum.xsl: template match eşleşmeleri bulamadı

<FlowDocument PagePadding="5,0,5,0" AllowDrop="True" NumberSubstitution.CultureSource="User" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> 
    <Paragraph>a</Paragraph> 
</FlowDocument> 

Ve bu XSLT'de: Bu Xaml girişli Örneğin beklenenden daha ziyade

<html> 
    <body> 
    a 
</body> 
</html> 

:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" 
> 

    <xsl:output method="html" indent="yes"/> 

    <xsl:template match="/"> 
    <html> 
     <body> 
     <xsl:apply-templates /> 
     </body> 
    </html> 
    </xsl:template> 

    <xsl:template match="FlowDocument"> 
    <xsl:apply-templates /> 
    </xsl:template> 

    <xsl:template match="Paragraph" > 
    <p> 
     <xsl:apply-templates /> 
    </p> 
    </xsl:template> 

bu çıktıyı almak

<html> 
    <body> 
     <p>a</p> 
    </body> 
</html> 

Olabilir Bu ad alanı ile ilgili bir sorun mu? Bu benim xsl dönüşümde ilk denemem, bu yüzden kaybettim.

cevap

20

Evet, ad alanı ile ilgili bir sorun var. Giriş belgenizdeki tüm öğeler http://schemas.microsoft.com/winfx/2006/xaml/presentation ad alanında. Şablonunuz, varsayılan ad alanında bulunan öğeleri eşleştirmeye çalışıyor ve bu, bulamıyor.

Bu ad alanını dönüştürmenizde bildirmeniz, bir önek atamanız ve sonra bu ön eki, bu ad alanındaki öğelerin eşleşmesi amaçlanan herhangi bir desende kullanmanız gerekir. Yani XSLT bu gibi görünmelidir:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
    xmlns:p="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    exclude-result-prefixes="msxsl"/> 

<xsl:output method="html" indent="yes"/> 

<xsl:template match="/"> 
    <html> 
    <body> 
     <xsl:apply-templates /> 
    </body> 
    </html> 
</xsl:template> 

<xsl:template match="p:FlowDocument"> 
    <xsl:apply-templates /> 
</xsl:template> 

<xsl:template match="p:Paragraph" > 
    <p> 
    <xsl:apply-templates /> 
    </p> 
</xsl:template> 
+0

Teşekkürler Robert - İsim alanını xsl: stylesheet etiketine eklemeyi denedim, ancak ad alanını eşleme alanına eklememiştim. – dmo

0

Çalışıyor Ben kaynak belgeden bu kaldırdığınızda: Ben son iki şablon hiç eşleştiriyor inanmıyorum

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 

. (Bir senin FlowDocument şablonunda <div> sarma gibi bir şey koyarak test edebilirsiniz.)

+0

FlowDocument doğrudan bir WPF RichTextBox'tan gelir, bu yüzden xslt dosyasında, kaynak manipüle edilmesinden ziyade kullanmayı tercih ederim. Ad alanını eklemek ve öğe eşleşme alanlarını nitelendirmek sorunu çözdü. – dmo

0

Sadece

değiştirmeyi deneyin: ile xsl dosyasında "xsl şablonu maçı = '/'"

etiketi

"xsl: template match = '*'"

Bu, arzu edilen çıktıyı vermelidir.