Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

generating XML from xsl

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
ccm_paper
Asked:
ccm_paper
  • 7
  • 7
1 Solution
 
sathishvCommented:
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
 
ccm_paperAuthor Commented:
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
 
sathishvCommented:
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
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!

 
ccm_paperAuthor Commented:
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
 
sathishvCommented:
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
 
ccm_paperAuthor Commented:
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
 
sathishvCommented:
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
 
ccm_paperAuthor Commented:
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
 
sathishvCommented:
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
 
ccm_paperAuthor Commented:
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
 
sathishvCommented:
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
 
ccm_paperAuthor Commented:
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
 
sathishvCommented:
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
 
ccm_paperAuthor Commented:
Hi sathis,
I will get back to u 2marow with detailed Information.
Thanks for co-operation.
regards
0
 
moduloCommented:
PAQed with points refunded (400)

modulo
Community Support Moderator
0

Featured Post

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!

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now