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

Re: variable comparison

Subject: Re: variable comparison
From: Mike Brown <mike@xxxxxxxx>
Date: Thu, 18 Jan 2001 14:05:48 -0700 (MST)
variable comparison
kapil wrote:
> the problem is that if in database if in project field 
> if there are more or three same name projects then in
> report i want single repeated name(means project name)
> in report and the details of all repeated projects in a order.
> means it needs variable comparison and after comparison
> i need ther records in order 

XSLT is generally for XML-to-XML conversion. When you speak of databases,
fields and reports, you are not talking about XML directly. To answer
your question, we will need to see your XML, and an example of the
output you want.

Your question sounds very much like a grouping FAQ, but the requirement
of only doing the grouping when there are 3 of the same name, rather than
2, makes it much more complicated. Is it really necessary?

Let's say you have XML like this:

<?xml version="1.0" encoding="utf-8"?>
<projects>
   <project id="p1">
     <project_name>Colors</project_name>
     <record>red</record>
     <record>orange</record>
     <record>yellow</record>
   </project>
   <project id="p2">
     <project_name>Fruits</project_name>
     <record>apple</record>
     <record>orange</record>
     <record>pear</record>
   </project>
   <project id="p3">
     <project_name>Colors</project_name>
     <record>green</record>
     <record>blue</record>
     <record>purple</record>
   </project>
</projects>

And you want to produce output that is an HTML fragment like this:

<h3>Colors</h3>
<ul>
<li>red
<li>orange
<li>yellow
<li>green
<li>blue
<li>purple
</ul>
<h3>Fruits</h3>
<ul>
<li>apple
<li>orange
<li>pear
</ul>

Then you would need a stylesheet like this:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

        <xsl:output method="html" indent="yes"/>

        <xsl:template match="projects">
           <xsl:for-each select="project/project_name[not(. = preceding::project_name)]">
              <h3>
                 <xsl:value-of select="."/>
              </h3>
              <ul>
                 <xsl:for-each select="/projects/project[project_name = current()]/record">
                    <li>
                       <xsl:value-of select="."/>
                    </li>
                 </xsl:for-each>
              </ul>
           </xsl:for-each>
        </xsl:template>

</xsl:stylesheet>



Re: variable comparison,

How to write a comparision of 2 objects represented by variables is
just something like

  $var1 = $var2

Whether this evaluates to true or false depends on what type of objects
$var1 and $var2 represent. The operator (=, !=, <, <=, >, >=) also
affects the outcome.



   - Mike
____________________________________________________________________
Mike J. Brown, software engineer at            My XML/XSL resources: 
webb.net in Denver, Colorado, USA              http://skew.org/xml/


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


Current Thread
  • variable comparison
    • kapil - Wed, 17 Jan 2001 02:02:08 -0500 (EST)
      • <Possible follow-ups>
      • kapil - Thu, 18 Jan 2001 04:19:26 -0500 (EST)
        • Mike Brown - Thu, 18 Jan 2001 16:05:41 -0500 (EST) <=

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.