[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Increment/decrement a variable in XSL

Subject: Increment/decrement a variable in XSL
From: "Shaik Zulfakhar Ali" <shaik@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 4 Apr 2002 16:39:25 +0900
xml increment
Hi All,

  I have written the files to compare two xml files contents, if the answer
is correct count it.

CompareFile.xml which loads user.xml and admin.xml.

 I am trying to compare user.xml (User entered Answers)  with admin.xml
 (Correct Answers).

 Getting problem in comparing each element and increment the number if the
 answer is correct.

 Is it possible to declare a variable globally and assign the value some
other
 place ?  For displaying the count ie Correct Answers at the end.


The files are as follows :

admin.xml:-

<?xml version="1.0" encoding="UTF-8"?>

<subjects>
 <subject>
  <no>1</no>
  <answer>Object Oriented</answer>
 </subject>
 <subject>
  <no>2</no>
  <answer>staticc</answer>
 </subject>
 <subject>
  <no>3</no>
  <answer>answer3</answer>
 </subject>
 <subject>
  <no>4</no>
  <answer>answer4</answer>
 </subject>
</subjects>
------------------------------------
user.xml:-

<?xml version="1.0" encoding="UTF-8"?>

<subjects>
 <subject>
  <no>1</no> <answer>Object Oriented</answer>
 </subject>
 <subject>
  <no>2</no> <answer>static</answer>
 </subject>
 <subject>
  <no>3</no> <answer>answer3</answer>
 </subject>
 <subject>
  <no>4</no> <answer>answer4</answer>
 </subject>
</subjects>
----------------------------------------
CompareFiles.xml:-

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="CompareFiles.xsl"?>

<files>
  <file href="user.xml" />
  <file href="admin.xml" />
</files>
-----------------------------------------
CompareFiles.xsl:-

<?xml version="1.0"?>

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

  <xsl:output method="html" />


     <xsl:template match="/">
   <xsl:variable name="user" select="document(/files/file[1]/@href, /)" />
   <xsl:variable name="admin" select="document(/files/file[2]/@href, /)" />

       <xsl:text>user contents</xsl:text> <br />
       <xsl:value-of select="$user" /> <br /> <br />

       <xsl:text>admin contents</xsl:text> <br />
       <xsl:value-of select="$admin" /> <br /><br />


    <xsl:if test="normalize-space($user/subjects/subject/no) =
normalize-space($admin/subjects/subject/no)">

      Both nos are equal <br />
      <xsl:value-of select="$user/subjects/subject/no" />  <br />

     <xsl:choose>

      <xsl:when test="normalize-space($user/subjects/subject/answer) =
normalize-space($admin/subjects/subject/answer)">


        Answer is matched <br /> <br />

        User Ans: <xsl:value-of select="$user/subjects/subject/answer" />
<br />
        Admin Ans:

       <xsl:variable name="CorrectAnswers">

        <xsl:value-of select="count($admin/subjects/subject/answer)" /> <br
/>

       </xsl:variable>

       No of Correct Answers: <xsl:value-of select="$CorrectAnswers" /> <br
/>


      </xsl:when>

      <xsl:otherwise>

        Answer is not matching <br /> <br />

        User Ans: <xsl:value-of select="$user/subjects/subject/answer" />
<br />
        Admin Ans: <xsl:value-of select="$admin/subjects/subject/answer" />
<br />

      </xsl:otherwise>

     </xsl:choose>

       </xsl:if>

     </xsl:template>

</xsl:stylesheet>

----------------------------------

Does anyone has idea how to solve this ?

Thanx in advance.

Zulfakhar



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.