Link to home
Start Free TrialLog in
Avatar of samir25
samir25

asked on

Urgent:how to use XSL

hi
i am using asp to extract data from the xml. teh data coming  is very less. say 10-15 lines. but the way it shows is not good. i know through stylesheets i can do that. but i really dont have a clue how to do it.

here is how i am fetching the data right now.
dim xNodeList
      dim xNode
      dim tmp
   Set xf = CreateObject("MSXML2.DOMDocument.4.0")       
   if sec = "Failed" then
            Set xNodeList=xdoc.selectNodes("//Data/Param/*/Pass[text()='false']")
      For i = 0 To xNodeList.length
            tmp = xnodeList(i).parentnode.nodename
            response.Write(xNodeList(i).parentnode.xml & "<br>")
      Next
end if
      
Avatar of steveberzins
steveberzins

what does the data look like?
what does 'good output' look like?
Avatar of samir25

ASKER

here is how i show by numbers

Total18 parameters Failed
1. LtFreqy GHz 16100 6100 GHz 1950 1950 false a
2. NuOfFreqs None 89 89 None 86 86 false a
3. TPower dBm 0 1 dBm 5.04 5.22 false a,b
4. TxMonitorError dB -0.5 0.5 dB 0.27 0.51 false a,b
5. BertRate11.35[GHz]O1.5[dB]RxPow-14[dBm] None 0 0.001 false a,i,l
6. Ber0[km]Bitte1.35[GHz]O13[dB]RxPow-14[dBm] None 0 0.0001 false a,i,l
7. Ber50[km]Bitte11.35[GHz]Or13[dB]RxPow-14[dBm] None 0 0.001 false a,i,l
8. Ber50[km]Bitte11.35[GHz]Or15[dB]RxPow-14[dBm] None 0 0.0001 false a,i,l
9. MaxErrorFeBitRae Gb*-1 11.36 INF Gb*s^-1 1.32 1.32 false a,x
10. PowerDisstion W 0 10.5 W 12.91 13.4 false a,b
11. PowerAmThresh dBm -15 -13 dBm -25.135 -25.135 false a,d
12. RPowerAlarmHresis dB 0.5 2.5 dB 0.053 0.053 false a,d,j
13. BoardTeperature-5[C] C -5 5 false b
14. BoardTerature70[C] C 65 80 false b
15. RBerDynamPower-2[dBm] None 0 0.004 false a,d,i,p,q,s
16. TFirmwareVer 01.104R1 99.ss2d1 false
17. LasFirmwareVer 02.003R7 02.004R7 false
18. FaFirmwareVer 01.004R1 01.001R1 false

so all these parameters i am getting from nodes.so all the parameters names shoudl come one below the other and all false should be one below the other. all columns should match ...
ok, how about the source data?
would make life a lot easier knowing what is going in, and what you want out.

so, probably a html table? that will help with lining up the columns...

Would it make sense to have a title row, that says what each column is?

It would at least help in developing, can be removed later if not wanted, but the more info we have to help getting the columns in order the easier to help.
Avatar of samir25

ASKER

here is the example of one node

  <ValueSpecification>
        <Name>LtFreqy </Name>
        <Specification>
          <Units>GHz</Units>
          <Min>16100</Min>
          <Max>6100</Max>
        </Specification>
<Measured>
          <Units>GHz</Units>
          <Min>16100</Min>
          <Max>6100</Max>
        </Measured>
        <Pass>false</Pass>
        <Note>a</Note>
      </ValueSpecification>
xsl:
<?xml version="1.0"?>
<xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" indent="yes"/>
      
      <xsl:template match="/Data/Param">
            <table border="1">
                  <tbody>
                        <tr>
                              <th>Name</th>
                              <th>Units</th>
                              <th>Min</th>
                              <th>Max</th>
                              <th>Units</th>
                              <th>Min</th>
                              <th>Max</th>
                              <th>Pass</th>
                              <th>Note</th>
                        </tr>
                        <xsl:apply-templates select="ValueSpecification[Pass[text() = 'false']]" />
                  </tbody>
            </table>
      </xsl:template>

      <xsl:template match="ValueSpecification">
            <tr>
                  <td><xsl:value-of select="Name/text()" /></td>
                  <td><xsl:value-of select="Specification/Units/text()" /></td>
                  <td><xsl:value-of select="Specification/Min/text()" /></td>
                  <td><xsl:value-of select="Specification/Max/text()" /></td>
                  <td><xsl:value-of select="Measured/Units/text()" /></td>
                  <td><xsl:value-of select="Measured/Min/text()" /></td>
                  <td><xsl:value-of select="Measured/Max/text()" /></td>
                  <td><xsl:value-of select="Pass/text()" /></td>
                  <td><xsl:value-of select="Note/text()" /></td>
            </tr>
      </xsl:template>
</xsl:stylesheet>

asp code that will take an xml doc, and transform it using an xsl:
<%

Dim xmlDoc
Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument.4.0")

Dim xslDoc
Set xslDoc = Server.CreateObject("MSXML2.DOMDocument.4.0")

xmlDoc.Load Server.MapPath("<<pathtoxmldatafile.xml>>")

'Check for a successful load of the XML Document.
If xmldoc.parseerror.errorcode <> 0 Then
  Response.Write "Error loading XML Document :<BR>"
  Response.Write "----------------------------<BR>"
  Response.Write "Error Code : " & xmldoc.parseerror.errorcode & "<BR>"
  Response.Write "Reason : " & xmldoc.parseerror.reason & "<BR>"
  Response.End
End If

xslDoc.Load Server.MapPath("<<pathtoxslttransformfile.xsl>>")

'Check for a successful load of the XSL Document.
If xsldoc.parseerror.errorcode <> 0 Then
  Response.Write "Error loading XSL Document :" & "<BR>"
  Response.Write "----------------------------" & "<BR>"
  Response.Write "Error Code : " & xsldoc.parseerror.errorcode & "<BR>"
  Response.Write "Reason : " & xsldoc.parseerror.reason & "<BR>"
  Response.Write "Line : " & xsldoc.parseError.line  & "<BR>"
  Response.Write "Line Pos : " & xsldoc.parseError.linepos & "<BR>"
  Response.Write "File Pos : " & xsldoc.parseError.filepos & "<BR>"
  Response.Write "Line : " & xsldoc.parseError.srcText & "<BR>"

 
  Response.End
End If

Response.Write xmlDoc.TransformNode(xslDoc)

%>

just replace the load lines, with the actual names/paths to your files, and all should be good.
Avatar of samir25

ASKER

how do i create an xsl. i have oxygen software. if i dont want to copy paste ur code and just refer it ..then how can i create it?
Avatar of samir25

ASKER

also...
what will happen if the nodes are not fixed?
it can be valueSpecification or RangeSpecification.
one can have more nodes than the other.
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of samir25

ASKER

so does it mean i dont need to use xpath in my asp and rather in my xsl?
also...i am getting the data from a clob in a query.. i am confused. how to refer it. though i will make change in my asp now
You only need XPath inside your XSLT,
if you don't use DOM methods next to your XSLT

XSLT is to transform the XML from one big chunk (likely your query result)
to another big chunck (the dynamic part part of your html page)

Steveberzins gave you the ASP code you need to do the transform
this line
xmlDoc.Load Server.MapPath("<<pathtoxmldatafile.xml>>")
should be changed to pick up the query result from Oracle instead of loading from a file,
unles you save that result to a file first

cheers

Geert
Avatar of samir25

ASKER

here is what i did in my asp which returns error
Set xNodeList=xdoc.selectNodes("//DataSheet/SummaryParameters/*/Pass[text()='false']")
response.write ("<h3>Failed Parameter List(" & xNodeList.length & "):</h3>")
For i = 0 To xNodeList.length
      data = xnodeList(i).parentnode.nodename
      response.Write(i+1 & "." & xNodeList(i).parentnode.xml & "<br>")
      xsl.load("http://" & Application("web_host") & "/xml/FailedTable.xsl")
      If xsl.parseerror.errorcode <> 0 Then
            Response.Write "Error loading XSL Document :" & "<BR>"
            Response.Write "----------------------------" & "<BR>"
            Response.Write "Error Code : " & xsl.parseerror.errorcode & "<BR>"
            Response.Write "Reason : " & xsl.parseerror.reason & "<BR>"
            Response.Write "Line : " & xsl.parseError.line  & "<BR>"
            Response.Write "Line Pos : " & xsl.parseError.linepos & "<BR>"
            Response.Write "File Pos : " & xsl.parseError.filepos & "<BR>"
            Response.Write "Line : " & xsl.parseError.srcText & "<BR>"
            Response.End
      End If
response.write(xf.transformNode(xsl))

i get this error
Error loading XSL Document :
----------------------------
Error Code : -2146697208
Reason : System error: -2146697208.
Line : 0
Line Pos : 0
File Pos : 0
Line :
you can't simply load an XSL from an http://
I recommend that you put the XSL locally,
so you can access it from the ServerMapPath
Avatar of samir25

ASKER

i copied this from my prev asp ex. so its ok to refer like i did. bec lot of asp pages are working like that
could be, I am not convinced, but I am not much of an ASP person,
so I assume you know better
The only thing I can think of then is that the XSLT is not valid
check your XSLT in Oxygen to see if it is valid
and make sure you are not working on a cached version of the XSLT
Avatar of samir25

ASKER

"check your XSLT in Oxygen to see if it is valid" how can i do this?
open the XSLT file in Oxygen and push the button with the red "V"
(validate document)
Avatar of samir25

ASKER

doc is valid. i removed the 1st line <?xml version="1.0"?>
but stil teh error is not gone. i have sent u the xsl just in case i missed soemthing
The XSLT is valid
and it errors when you load it,
maybe it is time to try the xsl.load with ServerMapPath as I suggested before
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial