tags:

views:

37

answers:

1

I need help transforming an XML file, whose part of it is with escape sequences, into HTML:

<?xml-stylesheet type=text/xsl href=XSL_17.xsl?>
<Root>
  <Book>
    <Author>John smith</Author>
    <Genre>Novel</Genre>
    <Details>&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Dets&gt;&lt;Ds&gt;&lt;D DN="Pages" DV="381" /&gt;&lt;D DN="Binding" DV="Hardcover" /&gt;&lt;D DN="Rate" DV="7.8" /&gt;&lt;/Ds&gt;&lt;/Dets&gt;</Details>
  </Book>
  <Car>
    <Year>2010</Year>
    <Name>Charger</Name>
    <Manufacturer>Dodge</Manufacturer>
  </Car>
</Root>

to the following HTML:

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
    <title></title>
</head>
<body>
    <table>
        <tr>
            <td><strong>Book</strong></td>
        </tr>
        <tr>
            <td><strong>Name</strong></td>
            <td><strong>Value</strong></td>
        </tr>
        <tr>
            <td>Author</td>
            <td>John smith</td>
        </tr>
        <tr>
            <td>Genre</td>
            <td>Novel</td>
        </tr>
        <tr>
            <td>Details</td>
            <td>
                <table>
                    <tr>
                        <td><strong>Name</strong></td>
                        <td><strong>Value</strong></td>
                    </tr>
                    <tr>
                        <td>Pages</td>
                        <td>381</td>
                    </tr>
                    <tr>
                        <td>Binding</td>
                        <td>Hardcover</td>
                    </tr>
                    <tr>
                        <td>Rate</td>
                        <td>7.8</td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <table>
        <tr>
            <td><strong>Car</strong></td>
        </tr>
        <tr>
            <td><strong>Name</strong></td>
            <td><strong>Value</strong></td>
        </tr>
        <tr>
            <td>Year</td>
            <td>2010</td>
        </tr>
        <tr>
            <td>Name</td>
            <td>Charger</td>
        </tr>
        <tr>
            <td>Manufacturer</td>
            <td>Dodge</td>
        </tr>
    </table>
</body>
</html>

I.e., I need to represent both normal XML and escaped XML in HTML tables.

+4  A: 

This cannot be done with XSLT unless one implements an XML parser in XSLT.

If you have Saxon, you can use the Saxon extensions saxon:parse() and saxon:transform()

Dimitre Novatchev
One *could* output the contents of `<Details>` with `disable-output-escaping="yes"` to a new document and then transform the result in a second step. I think that the XML declaration in the element contents is a bit of a problem, though (hard-coded encoding value).
Tomalak