Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Styling xml

Status
Not open for further replies.

tradewise

Programmer
Feb 11, 2003
10
GB
Any help on applying style to TableName (in this case AIRCRAFT) would be most appreciated:

...extract from source code .....

<?xml version="1.0" encoding="UTF-16"?>
<?xml-stylesheet type="text/css" href="test.css" ?>

<XML_Transfer>

<Table TableName="AIRCRAFT">
<Fields>
<Field>
<Name>AC_SERIAL_NO</Name>
<Type>200</Type>
<DefinedSize>8</DefinedSize>
<Precision>0</Precision>
<NumericScale>0</NumericScale>
</Field>
<Field>
<Name>AIRFRAME_HOURS</Name>
<Type>139</Type>
<DefinedSize>16</DefinedSize>
<Precision>0</Precision>
<NumericScale>0</NumericScale>
</Field>
</Fields>
<Row>
<AC_SERIAL_NO>XX001</AC_SERIAL_NO>
<AIRFRAME_HOURS>1846.704</AIRFRAME_HOURS>
</Row>
</Table>

I have several other tables to which I would like to apply different style.

I am happy with the other tags - just stuck with TableName.


 
Applying a stylesheet directly to an XML document may get inconsistent results between browsers. Modern ones (that is, not IE) should be able to cope with:
Code:
table[TableName="AIRCRAFT"] { foo: bar; }

A better approach would be to use XSLT (or similar) to transform the XML to regular HTML, then apply styling to that.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Thanks Chris,

tried it - no joy.

wrt XSLT, do you know of any good resource sites worth a look at?

 
Check out Apache Cocoon [cms], and Apache Ant [batch build].
PHP can also parse XML, as can most current scripting languages.

<marc>
New to Tek-Tips? Get better answers - faq581-3339
 
[1]
>tried it - no joy.
I think that's due to a typo. It should show in ff/nn.
>[red]T[/red]able[TableName="AIRCRAFT"] { foo: bar; }

[2]
As to using xsl, I can sketch a real dumb xsl to do it showing you the essential checking using xsl:if.
[tt]
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="<xsl:eek:utput method="html" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<html>
<body>
<h2>My Data</h2>
<table border="1">
<tr style="background-color:#00ff99">
<th>Name</th>
<th>Type</th>
<th>DefinedSize</th>
<th>Precision</th>
<th>NumericScale</th>
<th>AC_SERIAL_NO</th>
<th>AIRFRAME_HOURS</th>
</tr>
<xsl:for-each select="XML_Transfer/Table">
<xsl:if test="@TableName='AIRCRAFT'">
<tr style="background-color:#00ffff;">
<td>
<xsl:value-of select="Fields/Field/Name" />
</td>
<td>
<xsl:value-of select="Fields/Field/Type" />
</td>
<td>
<xsl:value-of select="Fields/Field/DefinedSize" />
</td>
<td>
<xsl:value-of select="Fields/Field/Precision" />
</td>
<td>
<xsl:value-of select="Fields/Field/NumericScale" />
</td>
<td>
<xsl:value-of select="Row/AC_SERIAL_NO" />
</td>
<td>
<xsl:value-of select="Row/AIRFRAME_HOURS" />
</td>
</tr>
</xsl:if>

<xsl:if test="not(@TableName='AIRCRAFT')">
<tr>
<td>
<xsl:value-of select="Fields/Field/Name" />
</td>
<td>
<xsl:value-of select="Fields/Field/Type" />
</td>
<td>
<xsl:value-of select="Fields/Field/DefinedSize" />
</td>
<td>
<xsl:value-of select="Fields/Field/Precision" />
</td>
<td>
<xsl:value-of select="Fields/Field/NumericScale" />
</td>
<td>
<xsl:value-of select="Row/AC_SERIAL_NO" />
</td>
<td>
<xsl:value-of select="Row/AIRFRAME_HOURS" />
</td>
</tr>
</xsl:if>
</xsl:for-each>

</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>[/tt]

The dumbness I referred to consists of repetition of td's, but it is more intuition to read as a demo. It can be made much more concise.

In the xml, replacing the line referencing to the css, do this instead.
[tt]
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
[/tt]
Then the renderment is ie/moz compatible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top