Results 1 to 2 of 2

Thread: A sample XSLT transformation from Qt rich text to XHTML

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default A sample XSLT transformation from Qt rich text to XHTML

    I like a clean xhtml code .... why? faster and bring him to other format... advantage
    QTextEdit html code, cold shower run only so:

    xslt code:
    xml Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    3. xmlns="http://www.w3.org/1999/xhtml"
    4. xmlns:dc="http://purl.org/dc/elements/1.1/"
    5. xmlns:cms="http://www.pulitzer.ch/2005/PuliCMS/1.0"
    6. xmlns:s="http://www.pulitzer.ch/2005/shop/shema/1.0/"
    7. xmlns:php="http://php.net/xsl"
    8. xmlns:dcterms="http://purl.org/dc/terms/"
    9. xmlns:regexp="http://exslt.org/regular-expressions"
    10. exclude-result-prefixes="dc dcterms regexp xmlns cms s php">
    11.  
    12. <xsl:output method="xhtml" encoding="utf-8"/>
    13. <!-- QTextEdit to xhtml [url]http://doc.trolltech.com/4.1/qtextedit.html[/url] -->
    14. <!-- Write by PPK-Webprogramm [url]www.ciz.ch[/url] -->
    15. <!-- replace class name to your own... -->
    16. <!-- <root><QTextEdit_html/></root> and convert here! -->
    17.  
    18. <!-- base root -->
    19. <xsl:template match="/">
    20. <xsl:apply-templates/>
    21. </xsl:template>
    22. <!-- base root -->
    23. <xsl:template match="root">
    24. <xsl:apply-templates/>
    25. </xsl:template>
    26.  
    27. <!-- span aberation -->
    28. <xsl:template match="span">
    29. <xsl:variable name="qtform" select="@style" />
    30. <xsl:if test="contains($qtform, 'underline')">
    31. <u>
    32. <xsl:apply-templates/>
    33. </u>
    34. </xsl:if>
    35. <xsl:if test="contains($qtform, 'italic')">
    36. <i>
    37. <xsl:apply-templates/>
    38. </i>
    39. </xsl:if>
    40. <xsl:if test="contains($qtform, 'font-weight')">
    41. <b>
    42. <xsl:apply-templates/>
    43. </b>
    44. </xsl:if>
    45. </xsl:template>
    46.  
    47. <!-- links href + target -->
    48. <xsl:template match="a">
    49. <!-- qlineedit remove target link.html#target=_self format -->
    50. <a>
    51. <xsl:attribute name="href"><xsl:value-of select="substring-before(@href,'#target=')" /></xsl:attribute>
    52. <xsl:attribute name="target"><xsl:value-of select="substring-after(@href,'#target=')" /></xsl:attribute>
    53. <xsl:apply-templates/>
    54. </a>
    55. </xsl:template>
    56.  
    57. <xsl:template match="div">
    58. <div class="UnaColonna">
    59. <xsl:apply-templates/>
    60. </div>
    61. </xsl:template>
    62.  
    63.  
    64. <xsl:template match="img">
    65. </xsl:template>
    66.  
    67. <xsl:template match="li">
    68. <li>
    69. <xsl:apply-templates/>
    70. </li>
    71. </xsl:template>
    72.  
    73. <xsl:template match="ol">
    74. <ul>
    75. <xsl:apply-templates/>
    76. </ul>
    77. </xsl:template>
    78.  
    79. <xsl:template match="ul">
    80. <ul>
    81. <xsl:apply-templates/>
    82. </ul>
    83. </xsl:template>
    84.  
    85. <!-- remove table on html or set to css2 but maintain to pdf apache xslt-fop -->
    86. <xsl:template match="table">
    87. <var class="_fo_table_">
    88. <xsl:apply-templates/>
    89. </var>
    90. </xsl:template>
    91. <xsl:template match="tr">
    92. <var class="_fo_table-row_">
    93. <xsl:apply-templates/>
    94. </var>
    95. </xsl:template>
    96. <xsl:template match="td">
    97. <var class="_fo_table-cell_">
    98. <xsl:apply-templates/>
    99. </var>
    100. </xsl:template>
    101. <!-- remove table -->
    102.  
    103. <!-- paragraph put your own classname to align paragraph -->
    104. <xsl:template match="p">
    105. <p>
    106. <xsl:if test="@align = 'center'">
    107. <xsl:attribute name="class">Centrato</xsl:attribute>
    108. </xsl:if>
    109. <xsl:if test="@align = 'justify'">
    110. <xsl:attribute name="class">Giustificato</xsl:attribute>
    111. </xsl:if>
    112. <xsl:if test="@align = 'right'">
    113. <xsl:attribute name="class">AllineaDestra</xsl:attribute>
    114. </xsl:if>
    115. <xsl:if test="@align = 'left'">
    116. <xsl:attribute name="class">AllineaSinistra</xsl:attribute>
    117. </xsl:if>
    118. <xsl:apply-templates/>
    119. </p>
    120. </xsl:template>
    121. <!-- paragraph -->
    122. </xsl:stylesheet>
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 20th June 2006 at 13:19. Reason: changed [ code ] to [ highlight = xml ]

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A sample XSLT transformation from Qt rich text to XHTML

    Best place for such examples is our wiki.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.