Altova Mailing List Archives


Re: Creating HTML from an XML and XSLT

From: "swapna guddanti [MSFT]" <swapnag@---------.--->
To: NULL
Date: 4/10/2006 6:02:00 PM

Following is an example to generate HTML output using XSLT on your input xml
docuemnt.
In the following xslt, I'm writing the orgdate attribute of the salesRep
node into a Date row in a table in the output.
The idea is to have your html tags interspersed with xslt. As far as xslt
code goes, you can have the top level amtch expression match salesRep node
as in
<xsl:template match="salesRep">
 and write out the xpath for the attribute /child nodes underneath it as
shown below.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="salesRep">
    <html>
    <body>
      <table border="1">
        <tr>
          <td>
            <xsl:value-of select="'Date'"/>
          </td>
          <td>
            <xsl:value-of select="@orgdate"/>
          </td>
        </tr>
      </table>
    </body>
    </html>
</xsl:template>
</xsl:stylesheet>

hope this helps,
swapna

"Thom Anderson" <thom@s...> wrote in message
news:u1k6MINXGHA.4920@T......
> Hi, I'm a newbee at XML so I need to ask this.  I have an xml data like
> follows.
>
> <?xml version="1.0" encoding="utf-8" ?>
> <salesRep repnum="123" orgdate="16">
>     <fname>Joe</fname>
>     <lname>Jones</lname>
>     <active>1</active>
>     <jobtitle>Sales Manager</jobtitle>
>     <alternateRepNumbers>
>         <alternateRepNum>124</alternateRepNum>
>         <alternateRepNum>125</alternateRepNum>
>         <alternateRepNum>128</alternateRepNum>
>     </alternateRepNumbers>
> </salesRep>
>
> I need to display it like this but I don't know how to create a transform
> XSLT document.  Can someone create it for me so I can understand it.  I
made
> this example easy I think.
>
> <html><body><table cellSpacing="0" cellPadding="10"
> border="1"><tr><td><table border="1"><tr><td colSpan="2">Date:
> 16</td></tr><tr><td colSpan="2">Rep&nbsp;Information: Joe
> Jones</td></tr><tr><td height="5"><B>Job Title:</B></td><td
eight="5">Sales
> Manager</td></tr><tr><td><B>Primary Rep
> Num:</B></td><td>123</td></tr><tr><td><B> Active
> Status:</B></td><td>Yes</td>
> </tr><tr valign="top"><td><B>Alternate Numbers</B></td><td><table
border="0"
> cellpadding="0"><tr><td>124</td>
>
</tr><tr><td>125</td></tr><tr><td>128</td></tr></table></td></tr></table></t
d></tr></table></body></html>
>
>


Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.