943,955 Members | Top Members by Rank

Ad:
Mar 18th, 2009
0

XSL elements from attributes

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RobertGaut is offline Offline
1 posts
since Mar 2009
Mar 19th, 2009
0

Re: XSL elements from attributes

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <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">
  3. <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
  4.  
  5. <xsl:template match="FlowControl">
  6. <body>
  7. <xsl:apply-templates select="Run" />
  8. </body>
  9. </xsl:template>
  10.  
  11. <xsl:template match="Run">
  12. <xsl:if test="@FontStyle = 'Italic'">
  13. <xsl:text disable-output-escaping="yes">&lt;em&gt;</xsl:text>
  14. </xsl:if>
  15. <xsl:if test="@FontWeight = 'Bold'">
  16. <xsl:text disable-output-escaping="yes">&lt;strong&gt;</xsl:text>
  17. </xsl:if>
  18. <xsl:value-of select="."/>
  19. <xsl:if test="@FontWeight = 'Bold'">
  20. <xsl:text disable-output-escaping="yes">&lt;/strong&gt;</xsl:text>
  21. </xsl:if>
  22. <xsl:if test="@FontStyle = 'Italic'">
  23. <xsl:text disable-output-escaping="yes">&lt;/em&gt;</xsl:text>
  24. </xsl:if>
  25. </xsl:template>
  26. </xsl:stylesheet>
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 731
Bite my shiny metal ass!
pritaeas is offline Offline
4,177 posts
since Jul 2006
Mar 20th, 2009
1

Re: XSL elements from attributes

Typo
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1.  
  2. <xsl:template match="FlowControl">
should be
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <xsl:template math="FlowDocument">
Reputation Points: 22
Solved Threads: 11
Junior Poster
fpmurphy is offline Offline
144 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: Xslt-escape_sequence
Next Thread in XML, XSLT and XPATH Forum Timeline: Namespaces with XPaths





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC