Frac
Frac

Reputation: 331

Use .xsl stylesheet to display XML generated from eclipse xsd in a web browser

There seems to be tons of information related to this topic, but none have helped me out yet :( I used eclipse to create an .xsd file to defile a schema for xml. This worked great. Then I generated an .xml file (in eclipse) and populated out some information. The XML file also looks good. The problem is that I want to display this XML file in a web browser (for easy reading) and I think I need an xsl stylesheet to do this. No matter what I try, I cannot dig any information out of my XML file. I have tried all sorts of namespace types of things I found on the net to no avail. Can someone please help me figure out how to code the .xsl to dig out data from my .xml file? Thanks SO MUCH in advance.

Here is a very simple xml file as an example:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="calibrationStylesheet.xsl"?>
<tns:calibration xmlns:tns="http://www.example.org/calibrationSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/calibrationSchema calibrationSchema.xsd ">
  <tns:Date>2013-07-16</tns:Date>
  <tns:Time>11:00:00</tns:Time>
  <tns:Temp>25.5</tns:Temp>
  <tns:hardware>
    <tns:NAnalyzers>4</tns:NAnalyzers>
    <tns:NGenerators>4</tns:NGenerators>
    <tns:NPorts>4</tns:NPorts>
    <tns:instr/>
  </tns:hardware>
  <tns:calGroup>
    <tns:calGroupType>Analysis</tns:calGroupType>
    <tns:pathLoss>
      <tns:pathName>PathName</tns:pathName>
    </tns:pathLoss>
  </tns:calGroup>
</tns:calibration>

and here is the xsl stylesheet. I am trying just to read out the Temp as an example, but would like to be able to read all of the data.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
 xmlns:xs="http://wwwe.w3.org/2001/XMLSchema" 
 xmlns:tns="http://www.example.org/calibrationSchema" 
 xs:schemaLocation="http://www.example.org/calibrationSchema calibrationSchema.xsd ">

    <xsl:template match="/">
        <html>
        <body>
        Hello
        <xsl:value-of select="//tns:calibration/Temp"></xsl:value-of>
        After
        </body> 
        </html>

    </xsl:template>
</xsl:stylesheet>

Its definitely a mess from me trying lots of things. How can I fix this? Thanks again.

Upvotes: 0

Views: 1156

Answers (1)

JLRishe
JLRishe

Reputation: 101738

If you have nodes that are in a namespace, you need to use the namespace prefix when referring to any of them, not just the top-level one:

<xsl:value-of select="tns:calibration/tns:Temp" />

Upvotes: 1

Related Questions