473,657 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can I simplify this?

Hi All,

Kind of new to this. What I have below works, but I am wondering if
there is a way to make it more efficient/simpler instead of having to
write an if, tr, td, blah for each datatype. How would I simplify this?
Any thoughts are appreciated.

Thanks,
Patrick

Datatypes will be at leat 1 but could be up to 10 depending on the setup.

<datacollecte d>
<datatype1>AD CP Velocity Measurements</datatype1>
<datatype2>AD CP Temperature</datatype2>
<datatype3>AD CP Performance DataX</datatype3>
<datatype4>Seab ird Microcat Data</datatype4>
<datatype5>WaDA R Temperature Data</datatype5>
<datatype6>Coas tal Climate MET Data</datatype6>
</datacollected>

<xsl:for-each select="./datacollected"< th align="left"
bgcolor="#28609 E">Data Collected</th>

<xsl:if test="datatype1 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datatyp e1"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype2 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datatyp e2"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype3 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datatyp e3"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype4 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datatyp e4"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype5 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datatyp e5"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype6 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datatyp e6"/></td><td align="center"> X</td>
</tr>
</xsl:if>
</xsl:for-each>
--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science
http://ocgweb.marine.usf.edu Phone: 727 553-3334

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld
Jun 8 '07 #1
6 1888
Patrick a écrit :
Kind of new to this. What I have below works, but I am wondering if
there is a way to make it more efficient/simpler instead of having to
write an if, tr, td, blah for each datatype. How would I simplify this?
Datatypes will be at leat 1 but could be up to 10 depending on the setup.

<datacollecte d>
<datatype1>AD CP Velocity Measurements</datatype1>
<datatype2>AD CP Temperature</datatype2>
<datatype3>AD CP Performance DataX</datatype3>
<datatype4>Seab ird Microcat Data</datatype4>
<datatype5>WaDA R Temperature Data</datatype5>
<datatype6>Coas tal Climate MET Data</datatype6>
</datacollected>

<xsl:if test="datatype1 ">
<xsl:if test="datatype2 ">
<xsl:if test="datatype3 ">
<xsl:if test="datatype4 ">
<xsl:if test="datatype5 ">
<xsl:if test="datatype6 ">
The *local name* of your elements is "datatype1" , "datatype2" ,
"datatype3" ... right ? So what about testing *any* element *whose* local
name *starts with* "datatype" ? ;-)

Cheers,

p.
Jun 8 '07 #2
Obvious simplification: Factor out the boilerplate -- use templates
rather than conditionals.

<xsl:for-each select="./datacollected">
<th align="left" bgcolor="#28609 E">Data Collected</th>
<xsl:apply-templates>
</xsl:for-each>

and add

<xsl:template match="datatype 1 | datatype2 | datatype3 | datatype4 |
datatype5 | datatype6">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="."/></td><td align="center"> X</td>
</tr>
</xsl:template>

This does assume the datatypeWhateve r elements will appear in the
desired order; if not, you can fix that by doing six more-selective
applyTemplates calls.

Actually, you might want to change whatever is calling the for-each to
also take advantage of apply-templates.

It is usually (but not always) better to let XSLT do the looping and
matching for you, and keep your own focus on "what do I want to do with
it once I've found it?"

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jun 8 '07 #3
On Jun 8, 8:24 pm, Patrick <psm...@marine. usf.eduwrote:
Hi All,

Kind of new to this. What I have below works, but I am wondering if
there is a way to make it more efficient/simpler instead of having to
write an if, tr, td, blah for each datatype. How would I simplify this?
Any thoughts are appreciated.

Thanks,
Patrick

Datatypes will be at leat 1 but could be up to 10 depending on the setup.

<datacollecte d>
<datatype1>AD CP Velocity Measurements</datatype1>
<datatype2>AD CP Temperature</datatype2>
<datatype3>AD CP Performance DataX</datatype3>
<datatype4>Seab ird Microcat Data</datatype4>
<datatype5>WaDA R Temperature Data</datatype5>
<datatype6>Coas tal Climate MET Data</datatype6>
</datacollected>

<xsl:for-each select="./datacollected"< th align="left"
bgcolor="#28609 E">Data Collected</th>

<xsl:if test="datatype1 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datatyp e1"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype2 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datatyp e2"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype3 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datatyp e3"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype4 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datatyp e4"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype5 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datatyp e5"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype6 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datatyp e6"/></td><td align="center"> X</td>
</tr>
</xsl:if>
</xsl:for-each>
--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group - USF - College of Marine Sciencehttp://ocgweb.marine.u sf.edu Phone: 727 553-3334

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld
<xsl:template match="/datacollected">
<table>
<th align="left" bgcolor="#28609 E">Data Type</th>
<th align="left" bgcolor="#28609 E">Data Collected</th>
<xsl:apply-templates select="*[contains(name() ,
'datatype')]"/>
</table>
</xsl:template>

<xsl:template match="*[contains(name() , 'datatype')]">
<tr>
<td class="dt" bgcolor="#92ADC 8">
<xsl:value-of select="."/>
</td>
<td align="center"> X</td>
</tr>
</xsl:template>

Jun 8 '07 #4
Joseph Kesselman wrote:
Obvious simplification: Factor out the boilerplate -- use templates
rather than conditionals.

<xsl:for-each select="./datacollected">
<th align="left" bgcolor="#28609 E">Data Collected</th>
<xsl:apply-templates>
</xsl:for-each>

and add

<xsl:template match="datatype 1 | datatype2 | datatype3 | datatype4 |
datatype5 | datatype6">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="."/></td><td align="center"> X</td>
</tr>
</xsl:template>

This does assume the datatypeWhateve r elements will appear in the
desired order; if not, you can fix that by doing six more-selective
applyTemplates calls.

Actually, you might want to change whatever is calling the for-each to
also take advantage of apply-templates.

It is usually (but not always) better to let XSLT do the looping and
matching for you, and keep your own focus on "what do I want to do with
it once I've found it?"
Thanks for your reply. I will take a look at this to see how it works. I
had read something, somewhere about template matching but it was kind of
confusing to me. This gives me a bit of an example to go on.

Patrick

--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science
http://ocgweb.marine.usf.edu Phone: 727 553-3334

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld

Jun 11 '07 #5
delirio wrote:
On Jun 8, 8:24 pm, Patrick <psm...@marine. usf.eduwrote:
>>Hi All,

Kind of new to this. What I have below works, but I am wondering if
there is a way to make it more efficient/simpler instead of having to
write an if, tr, td, blah for each datatype. How would I simplify this?
Any thoughts are appreciated.

Thanks,
Patrick

Datatypes will be at leat 1 but could be up to 10 depending on the setup.

<datacollecte d>
<datatype1>AD CP Velocity Measurements</datatype1>
<datatype2>AD CP Temperature</datatype2>
<datatype3>AD CP Performance DataX</datatype3>
<datatype4>Seab ird Microcat Data</datatype4>
<datatype5>WaDA R Temperature Data</datatype5>
<datatype6>Coas tal Climate MET Data</datatype6>
</datacollected>

<xsl:for-each select="./datacollected"< th align="left"
bgcolor="#286 09E">Data Collected</th>

<xsl:if test="datatype1 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datat ype1"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype2 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datat ype2"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype3 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datat ype3"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype4 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datat ype4"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype5 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datat ype5"/></td><td align="center"> X</td>
</tr>
</xsl:if>
<xsl:if test="datatype6 ">
<tr>
<td class="dt" bgcolor="#92ADC 8"><xsl:valu e-of
select="datat ype6"/></td><td align="center"> X</td>
</tr>
</xsl:if>
</xsl:for-each>
--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group - USF - College of Marine Sciencehttp://ocgweb.marine.u sf.edu Phone: 727 553-3334

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld


<xsl:template match="/datacollected">
<table>
<th align="left" bgcolor="#28609 E">Data Type</th>
<th align="left" bgcolor="#28609 E">Data Collected</th>
<xsl:apply-templates select="*[contains(name() ,
'datatype')]"/>
</table>
</xsl:template>

<xsl:template match="*[contains(name() , 'datatype')]">
<tr>
<td class="dt" bgcolor="#92ADC 8">
<xsl:value-of select="."/>
</td>
<td align="center"> X</td>
</tr>
</xsl:template>
Thanks for your reply. I will take a look at this as it is very similar
to the response I received from Kesselman.

Patrick

--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science
http://ocgweb.marine.usf.edu Phone: 727 553-3334

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld

Jun 11 '07 #6
Peyo wrote:
Patrick a écrit :
>Kind of new to this. What I have below works, but I am wondering if
there is a way to make it more efficient/simpler instead of having to
write an if, tr, td, blah for each datatype. How would I simplify this?

>Datatypes will be at leat 1 but could be up to 10 depending on the setup.

<datacollected >
<datatype1>AD CP Velocity Measurements</datatype1>
<datatype2>AD CP Temperature</datatype2>
<datatype3>AD CP Performance DataX</datatype3>
<datatype4>Seab ird Microcat Data</datatype4>
<datatype5>WaDA R Temperature Data</datatype5>
<datatype6>Coas tal Climate MET Data</datatype6>
</datacollected>

<xsl:if test="datatype1 ">
<xsl:if test="datatype2 ">
<xsl:if test="datatype3 ">
<xsl:if test="datatype4 ">
<xsl:if test="datatype5 ">
<xsl:if test="datatype6 ">


The *local name* of your elements is "datatype1" , "datatype2" ,
"datatype3" ... right ? So what about testing *any* element *whose* local
name *starts with* "datatype" ? ;-)

Cheers,

p.
Thanks Peyo, I will take a look at this.

Patrick

--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science
http://ocgweb.marine.usf.edu Phone: 727 553-3334

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld

Jun 11 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
1741
by: Alan | last post by:
I have many OR in the if statement, any method to simplify? if (val == 5 | val == 9 | val == 34 | val == 111 | val == 131 | .......) // .... thank you
29
2385
by: Flzw | last post by:
Alright, here is a simple function I coded, won't be hard understanding what it does, and YES, I know, you will probably tell me it's awful code, I would like to know how to write it better, maybe using stringstream ? here it is : std::string IntToDiskSpace( int size) { if (size < 1024) return IntToStr( size ) + " Bytes"; else if (size < 1048576) return IntToStr( size / 1024) + "KB";
0
1540
by: Stylus Studio | last post by:
Stylus Studio 6 XML Enterprise Edition Now Integrates with TigerLogic XDMS XQuery and Native XML Database Bedford, MA, -- Stylus Studio ( http://www.stylusstudio.com ), the industry-leading provider of XML development tools for advanced XML data integration, and Raining Data Corporation (NASDAQ: RDTA), a leading provider of reliable data management solutions, today announced a new partnership to accelerate and make easier development of...
0
2299
by: Stylus Studio | last post by:
DataDirect XQuery(TM) is the First Embeddable Component for XQuery That is Modeled after the XQuery API for Java(TM) (XQJ) BEDFORD, Mass.--Sept. 20, 2005--DataDirect Technologies (http://www.datadirect.com), the software industry leader in standards-based components for connecting applications to data and an operating unit of Progress Software Corporation, today announced the release of DataDirect XQuery(TM), the first embeddable...
8
3664
by: ben | last post by:
i have a bit of code, that works absolutely fine as is, but seems over complicated/long winded. is there anyway to shorten/simplify it? the code is below. description of it: it's like strcpy in that it copies one block of data to another block of data until the block that is being copied contains a zero/null. the difference with this code is that it's doing 4bits at a time (all the values are 4bits) and the two blocks of data may not be...
3
2844
by: Bob Bedford | last post by:
hello I'm looking for some functions or objects allowing to select-insert-update-delete from any table in a mysql database without the need to create a new query every time. Example: selectdatas(array('field1','field2','fieldn'),array('table1','tablen'),array('left join,idy','inner join, idx')) then the function build the query, execute it and then return an object with
6
1665
by: jsceballos | last post by:
Hello. I'm writing a proxy class, i.e: a class whose methods mostly delegate their functionality to other class object. Most of the methods (which are quite a lot) defined in the class would end up being: def thisIsTheMethodName(self): self._handlerClass.thisIsTheMethodName() The handler object is the same in all methods.
3
4139
by: tshad | last post by:
I have dataGrid that I am filling from a List Collection and need to sort it by the various columns. So I need to be able to sort the Collection and found that you have to set up your own sorting functions to make it work. I have build the following 3 sorting functions for the 3 columns and have to call each one specifically. I am trying to find a way to cut simplify the functions and calls to make this a more
1
6073
AmLegacy
by: AmLegacy | last post by:
I'm having a hard time figuring out how to simplify the fractions. Can anyone look at this code and see if you can see something I don't. //This is the fraction adding function void add_fractions (int a, int b, int c, int d, int *ansn, int *ansd) { //int e, x, y, rem, gcd; a = a*d; //numerator 1 * denominator 2 c = c*b; //numerator 2 * denominator 1 b = b*d; // denominator 1 * denominator 2 d = b; //denominator 2 = denominator 1
3
1381
by: Hvid Hat | last post by:
Hi I've got the following XSLT that works but I'm trying to figure out how to simplify it. There is only one Image, so I don't need the for-each-loop. Anyone? <xsl:for-each select="Data/img"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:attribute name="class">right</xsl:attribute>
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.