Solved

generating XML from xsl

Posted on 2004-08-26
16
224 Views
Last Modified: 2008-03-04
Hi,

I need to write an xsl file that is used to generate XML file.

I need to write something like this

XSL file gets a value pass of fail.

Depending on this value (either pass of fail) when xml file is generated
it should have appropriate link or html page where request is to be
directed.

Does anyone has a sample code, or link wherein i can get something like
what i want.

thanks in advance,

regards,
Shashank
0
Comment
Question by:ccm_paper
  • 7
  • 7
16 Comments
 
LVL 6

Expert Comment

by:sathishv
ID: 11904655
The following snippet generates a link depending on the parameter on the flag:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:param name="flag"/>

<xsl:template match="/">
<html>
<body>
<a><xsl:attribute name="href"><xsl:choose><xsl:when test="$flag='pass'">pass.html</xsl:when><xsl:otherwise>fail.html</xsl:otherwise></xsl:choose></xsl:attribute><xsl:value-of select="$param"/></a>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Hope this helps.

Cheers,
Sathish
0
 

Author Comment

by:ccm_paper
ID: 11905622
Hi satish,

Thanks for you for the keen interest shown.

In brief, my source code is using this xsl file to generate the xml file. MSXML 4.0 is used as parser.

The xsl file uses <xsl:stylesheet xmlnssl="http://www.w3.org/TR/WD-xsl">
Here if i changes the namespace it gives me a error.
I don't have much clue whether i can change the namespace. I tried to change
it in the xsl file but it gave me error
The namesspace used here is <xsl:stylesheet xmlnssl="http://www.w3.org/TR/WD-xsl">
which does not recognise param if i use it with my namespace.
Can u suggest any turnaround.

Thanks once again.

regards
0
 
LVL 6

Expert Comment

by:sathishv
ID: 11910171
When you change the namespace, remember to include the version attribute,

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

Could you post the error message you are getting?
0
 

Author Comment

by:ccm_paper
ID: 11910706
i have used the namespace with version i.e.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

I am getting this error.

Expected token 'eof' found '['. .-->[<--.='Application Does not Exist']

 
0
 
LVL 6

Expert Comment

by:sathishv
ID: 11910918
I think its not because of the namespace, should be a problem with XPATH used in the stylesheet. Could you post the entire stylesheet?
0
 

Author Comment

by:ccm_paper
ID: 11911085
Hi , here is the xsl file.Hope it will help you.Plz read the comment i have that i have written starting with your name.
Thanks

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">


<xsl:template match="/">
<html>

<!--display Host Name ,Time,Date in the title -->

<head>
<title>show Report-<xsl:value-of select="//Header/Host_Name"/>-
<xsl:value-of select="//Header/Time"/>-
<xsl:value-of select="//Header/Date"/>
</title>
</head>

<body>

<h2>Checks Report</h2>

<!-- Display All the Header Information in tabular form-->
<table border="1" cellpadding="0" cellspacing="0" width="100%">

<!-- some values i have deleted to focus on the issue-->
<tr>
<td>Date</td>
<td><xsl:value-of select="//Header/Date"/></td>
</tr>

</table>

<!-- the Overal Summary -->

<h4><xsl:value-of select="*/Overall_Summary"/></h4>


<h3>Summary</h3>
      <!--Display the Summary in a tabular form-->

      <table border="1" cellpadding="0" cellspacing="0" width="100%" align="center">
      
      <!--Display the column names of the summary -->
            <tr>
            <td><b>Check Type</b></td>
            <td><b>Passed</b></td>
        <td><b>Failed</b></td>
        <td><b>Warnings</b></td>
        <td><b>Not Executed</b></td>
        <td><b>Total</b></td>
            </tr>
            
      <!--Display the actual summary -->      
            <xsl:for-each select="*/Summary/*">
            <tr>
            <td><xsl:value-of select="@Type"/></td>
            <td><xsl:value-of select="@Passed"/></td>
        <td><xsl:value-of select="@Failed"/> </td>
        <td><xsl:value-of select="@Warnings"/></td>
        <td><xsl:value-of select="@Not_Executed"/></td>
        <td><xsl:value-of select="@Total"/></td>
        </tr>
       
            </xsl:for-each>
      </table>
 

<!--Display the Details Checks in tabular form -->

<xsl:for-each select="*/Installation-Checks/Software-Checks">

<!-- Display the contents in table -->
<table border="1" cellpadding="0" cellspacing="0" width="100%" align="center">
            <tr style="text-align:left">
                        <td><b>Check Name</b></td>
                        <td><b>Required Value</b></td>
                        <td><b>Actual Value</b></td>
                        <td><b>Result</b></td>
            </tr>
   <xsl:for-each select="cerity_check">
            
            
            <tr style="text-align:left">
                  <td> <xsl:value-of select="@Check-Name"/></td>
                  <td> <xsl:value-of select="@Expected-Value"/> </td>
                  <td><xsl:value-of select="@Actual-Value"/></td>
                  <td><xsl:value-of select="."/> </td>



<!--HERE I WANT TO COMPARE THE VALUE OF"<xsl:value-of select="."/>" IT WITH 'PASSED' OR 'FAILED' AND DEPENDING
ON THE RESULT HYPERLINK FAILED or PASSED (which i will be seeing in the .xml file) TO SOME OTHER HTML FILE -->





        </tr>
   </xsl:for-each>
</table>
 
</xsl:for-each>


</xsl:otherwise>
</xsl:choose>
 
</xsl:for-each>


</body>
</html>
</xsl:template>
</xsl:stylesheet>


0
 
LVL 6

Expert Comment

by:sathishv
ID: 11911753
In this case you are not using any parameter, right? So, straightaway you can insert the condition (without using xsl:param),

(replace the comment with the following segment)

<td>
<xsl:choose>
<xsl:when test=".='PASSED'"><a href='PASSED.htm'>PASSED</a></xsl:when>
<xsl:otherwise><a href='FAILED.htm'>FAILED</a></xsl:otherwise>
</xsl:choose>
</td>

(or)

<td>
<xsl:if test=".='PASSED'"><a href='PASSED.htm'>PASSED</a></xsl:if>
<xsl:if test=".='FAILED'"><a href='FAILED.htm'>FAILED</a></xsl:if>
</td>
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:ccm_paper
ID: 11912051
Hi sathis,

I tried with the line of code u send.
I am getting this error.

Expected token 'eof' found '='. .-->=<--Passed

Thanks and Regards
0
 
LVL 6

Expert Comment

by:sathishv
ID: 11912149
Try assigning the value to a variable and comparing the value:

<xsl:variable name="tagvalue" select="."/>
<xsl:if test="$tagvalue='PASSED'"></xsl:if>

BTW, how are you running the transformation?
0
 

Author Comment

by:ccm_paper
ID: 11912363
hi sathis,

I can't this syntax because the namaspace(that i am using) does not support variable
I am getting this error.

Keyword xsl:variable may not be used in namespace http://www.w3.org/TR/WD-xsl.

regards
0
 
LVL 6

Expert Comment

by:sathishv
ID: 11912432
Can you explain how you are running the transformation?

http://www.w3.org/TR/WD-xsl is a old namespace. The parser should support the http://www.w3.org/1999/XSL/Transform namespace.
0
 

Author Comment

by:ccm_paper
ID: 11912629
Hi sathis,

I have already a running code written in VC++ .It has some xml files which it uses from the code.
It uses the XSL file to generate the final report in XML.
I have given the code and told to provide the feature (of hyperlink which i explained above).
I don't know much about XSL/XSLT. and how i can change the namespace.I tried to change the namespace from the xsl (which i guess is wrong) but it gave me an error.

Does the above info of any help to you.
Regards

0
 
LVL 6

Expert Comment

by:sathishv
ID: 11912907
Sorry, I'm still not sure how the whole scheme works.

MSXML 4.0 definitely supports the new namespace. When you install latest versions of MSXML parser it needs to be installed in replacement mode (though this is given for MSXML 3.0 only) by running the tool (xmlinst.exe) given in the page:
http://www.microsoft.com/downloads/details.aspx?familyid=1e6185d7-e4e4-43b1-8056-0e5ecd15a88a&languageid=f49e8428-7071-4979-8a67-3cffcb0c2524&displaylang=en

Hope this helps.
0
 

Author Comment

by:ccm_paper
ID: 11913814
Hi sathis,
I will get back to u 2marow with detailed Information.
Thanks for co-operation.
regards
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12637547
PAQed with points refunded (400)

modulo
Community Support Moderator
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now