Subject: Re: [xsl] variable comparison From: Mike Brown <mike@xxxxxxxx> Date: Thu, 18 Jan 2001 14:05:48 -0700 (MST) |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] variable comparison, kapil | Thread | [xsl] concatenation of XML files, Ramanand Singh |
Re: [xsl] search & clone problem, Walter Torres | Date | Re: [xsl] RE: Determining the level, Mike Brown |
Month |