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.DOMDo cument.4.0 ")
if sec = "Failed" then
Set xNodeList=xdoc.selectNodes ("//Data/P aram/*/Pas s[text()=' false']")
For i = 0 To xNodeList.length
tmp = xnodeList(i).parentnode.no dename
response.Write(xNodeList(i ).parentno de.xml & "<br>")
Next
end if
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.DOMDo
if sec = "Failed" then
Set xNodeList=xdoc.selectNodes
For i = 0 To xNodeList.length
tmp = xnodeList(i).parentnode.no
response.Write(xNodeList(i
Next
end if
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[d Bm] None 0 0.001 false a,i,l
6. Ber0[km]Bitte1.35[GHz]O13[ dB]RxPow-1 4[dBm] None 0 0.0001 false a,i,l
7. Ber50[km]Bitte11.35[GHz]Or 13[dB]RxPo w-14[dBm] None 0 0.001 false a,i,l
8. Ber50[km]Bitte11.35[GHz]Or 15[dB]RxPo w-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 ...
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]
6. Ber0[km]Bitte1.35[GHz]O13[
7. Ber50[km]Bitte11.35[GHz]Or
8. Ber50[km]Bitte11.35[GHz]Or
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.
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.
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>
<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/Unit s/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/tex t()" /></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("MSXML 2.DOMDocum ent.4.0")
Dim xslDoc
Set xslDoc = Server.CreateObject("MSXML 2.DOMDocum ent.4.0")
xmlDoc.Load Server.MapPath("<<pathtoxm ldatafile. xml>>")
'Check for a successful load of the XML Document.
If xmldoc.parseerror.errorcod e <> 0 Then
Response.Write "Error loading XML Document :<BR>"
Response.Write "------------------------- ---<BR>"
Response.Write "Error Code : " & xmldoc.parseerror.errorcod e & "<BR>"
Response.Write "Reason : " & xmldoc.parseerror.reason & "<BR>"
Response.End
End If
xslDoc.Load Server.MapPath("<<pathtoxs lttransfor mfile.xsl> >")
'Check for a successful load of the XSL Document.
If xsldoc.parseerror.errorcod e <> 0 Then
Response.Write "Error loading XSL Document :" & "<BR>"
Response.Write "------------------------- ---" & "<BR>"
Response.Write "Error Code : " & xsldoc.parseerror.errorcod e & "<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(xslDo c)
%>
just replace the load lines, with the actual names/paths to your files, and all should be good.
<?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
</tbody>
</table>
</xsl:template>
<xsl:template match="ValueSpecification"
<tr>
<td><xsl:value-of select="Name/text()" /></td>
<td><xsl:value-of select="Specification/Unit
<td><xsl:value-of select="Specification/Min/
<td><xsl:value-of select="Specification/Max/
<td><xsl:value-of select="Measured/Units/tex
<td><xsl:value-of select="Measured/Min/text(
<td><xsl:value-of select="Measured/Max/text(
<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("MSXML
Dim xslDoc
Set xslDoc = Server.CreateObject("MSXML
xmlDoc.Load Server.MapPath("<<pathtoxm
'Check for a successful load of the XML Document.
If xmldoc.parseerror.errorcod
Response.Write "Error loading XML Document :<BR>"
Response.Write "-------------------------
Response.Write "Error Code : " & xmldoc.parseerror.errorcod
Response.Write "Reason : " & xmldoc.parseerror.reason & "<BR>"
Response.End
End If
xslDoc.Load Server.MapPath("<<pathtoxs
'Check for a successful load of the XSL Document.
If xsldoc.parseerror.errorcod
Response.Write "Error loading XSL Document :" & "<BR>"
Response.Write "-------------------------
Response.Write "Error Code : " & xsldoc.parseerror.errorcod
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(xslDo
%>
just replace the load lines, with the actual names/paths to your files, and all should be good.
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?
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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("<<pathtoxm ldatafile. 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
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("<<pathtoxm
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
ASKER
here is what i did in my asp which returns error
Set xNodeList=xdoc.selectNodes ("//DataSh eet/Summar yParameter s/*/Pass[t ext()='fal se']")
response.write ("<h3>Failed Parameter List(" & xNodeList.length & "):</h3>")
For i = 0 To xNodeList.length
data = xnodeList(i).parentnode.no dename
response.Write(i+1 & "." & xNodeList(i).parentnode.xm l & "<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.transfor mNode(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 :
Set xNodeList=xdoc.selectNodes
response.write ("<h3>Failed Parameter List(" & xNodeList.length & "):</h3>")
For i = 0 To xNodeList.length
data = xnodeList(i).parentnode.no
response.Write(i+1 & "." & xNodeList(i).parentnode.xm
xsl.load("http://" & Application("web_host") & "/xml/FailedTable.xsl")
If xsl.parseerror.errorcode <> 0 Then
Response.Write "Error loading XSL Document :" & "<BR>"
Response.Write "-------------------------
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.transfor
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
I recommend that you put the XSL locally,
so you can access it from the ServerMapPath
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
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
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)
(validate document)
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
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
and it errors when you load it,
maybe it is time to try the xsl.load with ServerMapPath as I suggested before
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
what does 'good output' look like?