Given the following XML:

<FlowDocument>
     <Run FontStyle="Italic" FontWeight="Bold">test</Run>
</FlowDocument>

How could I get this result?:

<body>
     <em><strong>test</strong></em>
</body>

Thanks in advance!

Recommended Answers

All 2 Replies

<?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="xml" indent="yes" omit-xml-declaration="yes"/>
	
    <xsl:template match="FlowControl">
        <body>
	<xsl:apply-templates select="Run" />
        </body>
    </xsl:template>

    <xsl:template match="Run">
        <xsl:if test="@FontStyle = 'Italic'">
            <xsl:text disable-output-escaping="yes">&lt;em&gt;</xsl:text>
        </xsl:if>
        <xsl:if test="@FontWeight = 'Bold'">
            <xsl:text disable-output-escaping="yes">&lt;strong&gt;</xsl:text>
        </xsl:if>
        <xsl:value-of select="."/>
        <xsl:if test="@FontWeight = 'Bold'">
            <xsl:text disable-output-escaping="yes">&lt;/strong&gt;</xsl:text>
        </xsl:if>
        <xsl:if test="@FontStyle = 'Italic'">
            <xsl:text disable-output-escaping="yes">&lt;/em&gt;</xsl:text>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

Typo

<xsl:template match="FlowControl">

should be

<xsl:template math="FlowDocument">
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.