Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT doesn't match h2 tag in C# win8 app
    primarykey
    data
    text
    <p>I'm building a Windows 8 app in C#. I'm converting HTML to XAML with the help of an XSLT file. I'm using <a href="https://github.com/MacawNL/WinRT-RichTextBlock.Html2Xaml" rel="nofollow">https://github.com/MacawNL/WinRT-RichTextBlock.Html2Xaml</a> to convert HTML to XAML. This works fine for all HTML tags i've been using except for H2 (or H3 for that matter). </p> <p>My XSLT file looks like this: </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" exclude-result-prefixes="msxsl" &gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;!-- The html root element must be div, it translates to a xaml richtextblock.--&gt; &lt;xsl:template match="/div" priority="9"&gt; &lt;RichTextBlock&gt; &lt;RichTextBlock.Resources&gt; &lt;Style x:Key="Bullet" TargetType="Ellipse"&gt; &lt;Setter Property="Fill" Value="Black" /&gt; &lt;Setter Property="Width" Value="6" /&gt; &lt;Setter Property="Height" Value="6" /&gt; &lt;Setter Property="Margin" Value="-30,0,0,1" /&gt; &lt;/Style&gt; &lt;Style x:Key="Link" TargetType="HyperlinkButton"&gt; &lt;Setter Property="Foreground" Value="#ff6600" /&gt; &lt;Setter Property="BorderThickness" Value="1" /&gt; &lt;Setter Property="FontSize" Value="14" /&gt; &lt;Setter Property="Margin" Value="-15,-11" /&gt; &lt;/Style&gt; &lt;/RichTextBlock.Resources&gt; &lt;xsl:if test="normalize-space(text()) != ''"&gt; &lt;Paragraph&gt;&lt;xsl:value-of select="normalize-space(text())" /&gt;&lt;/Paragraph&gt; &lt;/xsl:if&gt; &lt;xsl:apply-templates select="/div/*" /&gt; &lt;/RichTextBlock&gt; &lt;/xsl:template&gt; &lt;xsl:template match="div" priority="0"&gt; &lt;Span&gt;&lt;xsl:apply-templates /&gt;&lt;/Span&gt; &lt;/xsl:template&gt; &lt;!-- XAML Paragraphs cannot contain paragraphs, so we convert top-level html paragraphs to xaml paragraphs and convert nested html paragraphs to xaml spans with linebreaks --&gt; &lt;xsl:template match="/div/P | /div/p" priority="9"&gt; &lt;Paragraph LineStackingStrategy="MaxHeight" Foreground="Black"&gt;&lt;xsl:apply-templates /&gt; &lt;LineBreak /&gt; &lt;/Paragraph&gt; &lt;/xsl:template&gt; &lt;xsl:template match="P | p" priority="0"&gt; &lt;Paragraph LineStackingStrategy="MaxHeight" Foreground="Black"&gt;&lt;LineBreak /&gt;&lt;xsl:apply-templates /&gt;&lt;LineBreak /&gt;&lt;/Paragraph&gt; &lt;/xsl:template&gt; &lt;xsl:template match="h2 | H2"&gt; &lt;Paragraph&gt; &lt;Bold FontSize="56" Foreground="Black"&gt; &lt;xsl:apply-templates /&gt; &lt;/Bold&gt; &lt;LineBreak/&gt; &lt;/Paragraph&gt; &lt;/xsl:template&gt; &lt;!-- The RichTextBlock XAML element can contain only paragraph child elements, so any unknown html child elements of the root element will become XAML paragraphs --&gt; &lt;xsl:template match="/div/*"&gt; &lt;Paragraph LineStackingStrategy="MaxHeight" Foreground="Black"&gt;&lt;xsl:apply-templates /&gt;&lt;/Paragraph&gt; &lt;/xsl:template&gt; &lt;!-- Lists can only occur outside paragraphs, at the top level --&gt; &lt;xsl:template match="/div/UL | /div/ul"&gt; &lt;Paragraph Foreground="Black" Margin="20,0,0,0"&gt;&lt;LineBreak /&gt;&lt;xsl:apply-templates /&gt;&lt;/Paragraph&gt; &lt;/xsl:template&gt; &lt;xsl:template match="LI | li"&gt; &lt;Span&gt;&lt;InlineUIContainer&gt;&lt;Ellipse Style="{{StaticResource Bullet}}"/&gt;&lt;/InlineUIContainer&gt;&lt;xsl:apply-templates /&gt;&lt;LineBreak /&gt;&lt;/Span&gt; &lt;/xsl:template&gt; &lt;xsl:template match="B | b"&gt; &lt;Bold FontSize="56"&gt;&lt;xsl:apply-templates /&gt;&lt;/Bold&gt; &lt;/xsl:template&gt; &lt;xsl:template match="STRONG | strong"&gt; &lt;Bold FontSize="20" Foreground="Black"&gt; &lt;xsl:apply-templates /&gt; &lt;/Bold&gt; &lt;/xsl:template&gt; &lt;xsl:template match="I | i"&gt; &lt;Italic&gt;&lt;xsl:apply-templates /&gt;&lt;/Italic&gt; &lt;/xsl:template&gt; &lt;xsl:template match="U | u"&gt; &lt;Underline&gt;&lt;xsl:apply-templates /&gt;&lt;/Underline&gt; &lt;/xsl:template&gt; &lt;xsl:template match="BR | br"&gt; &lt;LineBreak /&gt; &lt;/xsl:template&gt; &lt;xsl:template match="A | a"&gt; &lt;Span&gt;&lt;InlineUIContainer&gt;&lt;HyperlinkButton Style="{{StaticResource Link}}"&gt;&lt;xsl:attribute name="NavigateUri"&gt;&lt;xsl:value-of select="@href"/&gt;&lt;/xsl:attribute&gt;&lt;xsl:apply-templates /&gt;&lt;/HyperlinkButton&gt;&lt;/InlineUIContainer&gt;&lt;/Span&gt; &lt;/xsl:template&gt; &lt;xsl:template match="IMG | img"&gt; &lt;InlineUIContainer&gt;&lt;Image MaxHeight="480" Margin="0,20,0,10" Stretch="Uniform" &gt;&lt;xsl:attribute name="Source"&gt;&lt;xsl:value-of select="@src"/&gt;&lt;/xsl:attribute&gt;&lt;xsl:apply-templates /&gt;&lt;/Image&gt;&lt;/InlineUIContainer&gt; &lt;/xsl:template&gt; &lt;!-- Note that by default, the text content of any unmatched HTML elements will be copied in the XAML. --&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>I've tried about any opties I could find but none of them work. Any idea how I can match the H2 tag in such way i can convert it to XAML?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload