• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

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
      
0
samir25
Asked:
samir25
  • 9
  • 6
  • 4
2 Solutions
 
steveberzinsCommented:
what does the data look like?
what does 'good output' look like?
0
 
samir25Author Commented:
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 ...
0
 
steveberzinsCommented:
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
samir25Author Commented:
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>
0
 
steveberzinsCommented:
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.
0
 
samir25Author Commented:
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?
0
 
samir25Author Commented:
also...
what will happen if the nodes are not fixed?
it can be valueSpecification or RangeSpecification.
one can have more nodes than the other.
0
 
Geert BormansCommented:
Oxygen is very good for this (XSLT, not the ASP)

Open the XML file in Oxygen,
create a new XSLT file (choose XSLT1, ASP does not allow XSLT2)
Then start the XSLT debugger by pressing the menu button, carrying a little box "XSLT"

Now you can start developping the XSLT, and test it by pushing the blue arrow
on the left

First you need an output method
if you are creating html, do:
<xsl:output method="html" indent="yes"/>

Then add a tempate for "/", that is your starting point

I prefer to build XSLTs using a push technique (pushing childnodes to seperate templates using apply-templates)
This way you get the most modular XSLT possible

So inside the template for "/", I do some main work (such as outputting the table element)
and I push the childnodes out, to the next template

That would be something like this
    <xsl:template match="/">
        <table border="1">
            <xsl:apply-templates select="//ValueSpecification" />
        </table>
    </xsl:template>

On the level of ValueSpecification, you have to create a row
That would be the next template
    <xsl:template match="ValueSpecification">
        <tr>
            <xsl:apply-templates/>
        </tr>
    </xsl:template>

Specification and Measured are just container elements,
so we just push the child nodes out without doing something with the container element
<xsl:template match="Specification | Measured">
    <xsl:apply-templates />
</xsl:template>

all the other elements are cells    
    <xsl:template match="*">
        <td><xsl:value-of select="."/></td>
    </xsl:template>

do you see how the row builds up?

Now you can add the header row...

Hope this gives you an approach
cheers

Geert



0
 
samir25Author Commented:
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
0
 
Geert BormansCommented:
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
0
 
samir25Author Commented:
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 :
0
 
Geert BormansCommented:
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
0
 
samir25Author Commented:
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
0
 
Geert BormansCommented:
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
0
 
samir25Author Commented:
"check your XSLT in Oxygen to see if it is valid" how can i do this?
0
 
Geert BormansCommented:
open the XSLT file in Oxygen and push the button with the red "V"
(validate document)
0
 
samir25Author Commented:
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
0
 
Geert BormansCommented:
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
0
 
steveberzinsCommented:
yes, lets try to get it just working, then once we know the pieces work, you can make it work how you want, by putting the pieces elsewhere if that makes sense.

so,

step one, load your xml.
since it sounds like you're getting xml from somewhere, use the loadXML method to load an xml string into the doc.

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

step two, load the xsl.
assuming you saved the xsl file somewhere near/relatively near the .asp page.

Dim xslDoc
Set xslDoc = CreateObject("MSXML2.DOMDocument.4.0")
xslDoc.load Server.MapPath("<<pathtoxslfilehere>>")

step three, perform the transform and write out the result
simple as this:
Response.Write xmlDoc.TransformNode(xslDoc)

---------

it would sure help if this didn't feel like pulling teeth to get information from you.
If there is different data, then give us enough of the data that we could reasonably determine that, and what the extra columns would be named, etc.

in my xsl, you could match on either with a couple small tweaks.

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="node()[Pass[text() = 'false']]" />
                  </tbody>
            </table>
      </xsl:template>

      <xsl:template match="ValueSpecification|RangeSpecification">
            <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>

Gertone's comments are good ones, it would be better design to build it up as he does, but I'm just trying to keep it simpler, and more straightforward, so you can see everything and not be as easily confused.

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 9
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now