xml - FlowDocument to HTML transformation - how do I select the foreground color in XSLT? -
i have adapted , extended xslt this answer this:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl x"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> <xsl:template match="x:section[not(parent::x:section)]"> <div> <xsl:apply-templates select="node()"/> </div> </xsl:template> <xsl:template match="x:section"> <xsl:apply-templates select="node()"/> </xsl:template> <xsl:template match="x:paragraph"> <p> <xsl:apply-templates select="node()"/> </p> </xsl:template> <xsl:template match="x:run"> <xsl:variable name="style"> <xsl:if test="@fontstyle='italic'"> <xsl:text>font-style:italic;</xsl:text> </xsl:if> <xsl:if test="@fontweight='bold'"> <xsl:text>font-weight:bold;</xsl:text> </xsl:if> <xsl:if test="contains(@textdecorations, 'underline')"> <xsl:text>text-decoration:underline;</xsl:text> </xsl:if> <xsl:if test="@fontsize != ''"> <xsl:text>font-size:</xsl:text> <xsl:value-of select="@fontsize" /> <xsl:text>pt;</xsl:text> </xsl:if> <xsl:if test="@fontfamily != ''"> <xsl:text>font-family:</xsl:text> <xsl:value-of select="@fontfamily" /> <xsl:text>;</xsl:text> </xsl:if> <xsl:if test="@foreground-color != ''"> <xsl:text>color:</xsl:text> <xsl:value-of select="@foreground-color"/> <xsl:text>;</xsl:text> </xsl:if> </xsl:variable> <span> <xsl:if test="normalize-space($style) != ''"> <xsl:attribute name="style"> <xsl:value-of select="normalize-space($style)"/> </xsl:attribute> </xsl:if> <xsl:value-of select="text()"/> </span> </xsl:template> </xsl:stylesheet>
this xslt works perfectly, except part:
<xsl:if test="@foreground-color != ''"> <xsl:text>color:</xsl:text> <xsl:value-of select="@foreground-color"/> <xsl:text>;</xsl:text> </xsl:if>
apart foreground-color, have tried color , fontcolor, nothing seems work.
what correct keyword after "test=" , "select=" extract text foreground color?
it more css problem xslt problem create html css inline styles. correct property name in css indeed color
part correct. don't know color values input format uses , whether equal color names css understands. show sample of input , check css color property value spec: http://www.w3.org/tr/css2/syndata.html#value-def-color.
as attribute, based on http://msdn.microsoft.com/en-us/library/system.windows.documents.textelement.foreground.aspx attribute might be
<xsl:if test="@foreground != ''"> <xsl:text>color:</xsl:text> <xsl:value-of select="@foreground"/> <xsl:text>;</xsl:text> </xsl:if>
i haven't checked possible color values , match css values.
Comments
Post a Comment