Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XSLT to HTML

XSLT to HTML

Scheduled Pinned Locked Moved XML / XSL
xmlhtmlcssdatabasehelp
2 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vho123
    wrote on last edited by
    #1

    Hi programmers, i have this task that has been troubling me due to my limited knowledge of XML/XSLT. My task is to create an XSLT(dictionary.xslt) file that will use an XML(translation.xml) file as input which in turn will generate a desired HTML(dictionary.html) file like the one below. - The index must be sorted alphabetically. This index serves as a Table Of Contents which allows users to browse through all 'initials' available in this dictionary. - For each 'initial', the correct number of 'search' terms must be returned. - I will be able to do the css styling but as for the xslt code and functions i have little clue, i'd appreciate if someone here with the knowledge will be able to help me with this. --- input XML (translation.xml) -----

    <?xml version="1.0" encoding="UTF-8"?>
    <Dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="translation.xsd">
    <from>EN</from>
    <to>ES</to>
    <total>150</total>
    <translation initial="A">
    <search>A Clockwork Orange</search>
    <counter>1</counter>
    <replace>La naranja mecánica</replace>
    </translation>
    <translation initial="A">
    <search>A Few Good Men</search>
    <counter>1</counter>
    <replace>A Few Good Men</replace>
    </translation>
    <translation initial="A">
    <search>A Star Is Born</search>
    <counter>1</counter>
    <replace>Ha nacido una estrella</replace>
    </translation>
    <translation initial="A">
    <search>Ab Urbe condita</search>
    <counter>1</counter>
    <replace>Ab Urbe condita libri</replace>
    </translation>
    <translation initial="A">
    <search>Ab urbe condita</search>
    <counter>1</counter>
    <replace>Ab urbe condita</replace>
    </translation>
    <translation initial="A">
    <search>Abel</search>
    <counter>2</counter>
    <replace>Abel</replace>
    <replace>Caín</replace>
    </translation>
    <translation initial="B">
    <search>Batman & Robin</search>
    <counter>1</counter>
    <replace>Batman y Robin</replace>
    </translation>
    <translation initial="B">
    <search>Bomarzo</search>
    <counter>1<

    S 1 Reply Last reply
    0
    • V vho123

      Hi programmers, i have this task that has been troubling me due to my limited knowledge of XML/XSLT. My task is to create an XSLT(dictionary.xslt) file that will use an XML(translation.xml) file as input which in turn will generate a desired HTML(dictionary.html) file like the one below. - The index must be sorted alphabetically. This index serves as a Table Of Contents which allows users to browse through all 'initials' available in this dictionary. - For each 'initial', the correct number of 'search' terms must be returned. - I will be able to do the css styling but as for the xslt code and functions i have little clue, i'd appreciate if someone here with the knowledge will be able to help me with this. --- input XML (translation.xml) -----

      <?xml version="1.0" encoding="UTF-8"?>
      <Dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="translation.xsd">
      <from>EN</from>
      <to>ES</to>
      <total>150</total>
      <translation initial="A">
      <search>A Clockwork Orange</search>
      <counter>1</counter>
      <replace>La naranja mecánica</replace>
      </translation>
      <translation initial="A">
      <search>A Few Good Men</search>
      <counter>1</counter>
      <replace>A Few Good Men</replace>
      </translation>
      <translation initial="A">
      <search>A Star Is Born</search>
      <counter>1</counter>
      <replace>Ha nacido una estrella</replace>
      </translation>
      <translation initial="A">
      <search>Ab Urbe condita</search>
      <counter>1</counter>
      <replace>Ab Urbe condita libri</replace>
      </translation>
      <translation initial="A">
      <search>Ab urbe condita</search>
      <counter>1</counter>
      <replace>Ab urbe condita</replace>
      </translation>
      <translation initial="A">
      <search>Abel</search>
      <counter>2</counter>
      <replace>Abel</replace>
      <replace>Caín</replace>
      </translation>
      <translation initial="B">
      <search>Batman & Robin</search>
      <counter>1</counter>
      <replace>Batman y Robin</replace>
      </translation>
      <translation initial="B">
      <search>Bomarzo</search>
      <counter>1<

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      This does most of what you want...I've put in comments to show the different bits...

      <?xml version="1.0" encoding="utf-8" ?>
      <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" indent="yes"/>

      <!-- We need a template matching the document root to start the transformation -->
      <xsl:template match="/">
      <html>
      <head>
      <title>Bilingual Lexicon ES-EN</title>
      <link href="dictionary.css" rel="stylesheet" type="text/css" />
      </head>
      <body>
      <h3>Browse by letter</h3>
      <table>
      <!-- Process each translation element, sorted by the initial attribute and then the English term -->
      <xsl:apply-templates select="//translation">
      <xsl:sort select="@initial"/>
      <xsl:sort select="search"/>
      </xsl:apply-templates>
      </table>
      </body>
      </html>
      </xsl:template>

      <!-- Template to process a translation element -->
      <xsl:template match="translation">
      <!--
      If this is the first translation element, or its initial attribute is different
      to the last one in the list of translation elements, output the
      initial attribute.
      -->
      <xsl:if test="position()=1 or @initial != preceding-sibling::translation[1]/@initial">
      <tr><td colspan="2"><h1><xsl:value-of select="@initial"/></h1></td></tr>
      </xsl:if>
      <!-- Output a row for each translation -->
      <tr>
      <td><xsl:value-of select="search"/></td>
      <td>
      <!-- Output the first replace element -->
      <xsl:value-of select="replace[1]"/>
      <!-- Output the other replace elements preceded by the separator -->
      <xsl:for-each select="replace[position()>1]">
      ;<xsl:value-of select="."/>
      </xsl:for-each>
      </td>
      </tr>
      </xsl:template>
      </xsl:stylesheet>

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups