473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Match attribute values (columns) to column names

Hi,

I have found a way to map attributes (columns) to column headings. But
this runs really slow. Is there a way to improve it?

Thanks,
Carl

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xslt"?>
<root>
<Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name="lookup" content="empty" model="closed">
<AttributeType name="col1" dt:type="i2"/>
<AttributeType name="col2" dt:type="i2"/>
<AttributeType name="col3" dt:type="i2"/>
<AttributeType name="col4" dt:type="i2"/>
<AttributeType name="col5" dt:type="i2"/>
<attribute type="col1"/>
<attribute type="col2"/>
<attribute type="col3"/>
<attribute type="col4"/>
<attribute type="col5"/>
</ElementType>
</Schema>
<lookup xmlns="x-schema:#Schema1" col1="a" col2="b" col3="c"/>
<lookup xmlns="x-schema:#Schema1" col1="d" col3="e" col5="f"/>
<lookup xmlns="x-schema:#Schema1" col4="g"/>
</root>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:data="x-schema:#Schema1"
xmlns:schema="urn:schemas-microsoft-com:xml-data"
xmlns:user="http://mycompany.com/mynamespace"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">

<msxsl:script language="JScript" implements-prefix="user">
var numcols=0; var datacol=0; var HeadingCols = new Array();
function addHeadingColumn(node) {
numcols++;
HeadingCols[numcols-1] = node;
return HeadingCols[numcols-1];
}
function getHeadingColumn() {return HeadingCols[datacol];}
function resetDataColumn(){datacol=0; return '';}
function addDataColumn(){datacol++; return '';}
</msxsl:script>

<xsl:template match="/root">
<TABLE>
<xsl:apply-templates select="schema:Schema" /> <!-- headings -->
<xsl:apply-templates select="data:lookup" /> <!-- data -->
</TABLE>
</xsl:template>

<xsl:template match="schema:Schema">
<tr style="color:White;background-color:Blue;">
<td></td>
<xsl:for-each select="*/*"><!-- Select all the elements of the
schema-->
<xsl:if test="name(.)='AttributeType'"><!-- only pick the
AttributeType elements, otherwise you will have the columns twice -->
<xsl:for-each select="@name">
<xsl:if test=". != 'col1'">
<xsl:variable name="addHeading1"
select="user:addHeadingColumn(.)"/>
<td>
<xsl:attribute name="name"><xsl:value-of
select="."/></xsl:attribute>
<xsl:value-of select="."/>
</td>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
<td></td>
</tr>
</xsl:template>

<!-- lookup Template -->
<xsl:template match="data:lookup">
<xsl:variable name="resetDataColumn"
select="user:resetDataColumn()"/>
<tr>
<td></td>
<xsl:for-each select="@*">
<xsl:if test="name(.) != 'col1'">
<xsl:call-template name="whileloop">
<xsl:with-param name="MatchColumn" select="name(.)" />
</xsl:call-template>
<xsl:variable name="addDataColumn" select="user:addDataColumn()"/>
<td><xsl:value-of select="."/></td>
</xsl:if>
</xsl:for-each>
<td></td>
</tr>
</xsl:template>

<!-- While loop -->
<xsl:template name="whileloop">
<xsl:param name="MatchColumn" />
<!-- put the code to execute here -->
<xsl:variable name="HeadingColumn"
select="user:getHeadingColumn()"/>
<!-- code to execue ends here -->
<!-- put the comparison to make here -->
<xsl:if test="$MatchColumn != $HeadingColumn">
<!-- comparison ends here -->
<xsl:variable name="addDataColumn" select="user:addDataColumn()"/>
<td></td>
<xsl:call-template name="whileloop">
<xsl:with-param name="MatchColumn" select="$MatchColumn" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Jul 20 '05 #1
0 2159

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

Similar topics

2
by: Isz | last post by:
Hi Group: I would like to know if it is possible to change the name of an attribute to something else. My setup is like this: I have serveral SQL tables that I nest and join so that it all...
5
by: Brian Henry | last post by:
I have a messaging application that has a data grid with information like an email list would have (from, subject, time sent, size) but the subject could be very long in theory, and then it would...
13
by: scorpion53061 | last post by:
Very urgent and I am very close but need a little help to get me over the edge........ I need to write these columns to a html file with each row containing these columns (seperated by breaks)....
6
by: Marcel Hug | last post by:
Hi all ! I have a table in my database, which has 3 attributes. IDFailureControl, ControlDate and ControlVersion. In the following function I test, if the date of today allready exists. Then I...
2
by: luke.crouch | last post by:
My server-side php script is generating an xml response with the following structure: <thread class='Columns'> <Id class='Column dataDetail'>12345</Id> <Command class='Column...
1
by: JJ | last post by:
Is it possible to count the number of columns that match certain conditions and return a single value? For example in the database we have a record where: Column 1 = Male Column 2 = A Column...
0
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL,...
11
by: ankitmathur | last post by:
Hi, I'm trying to overcome a situation whereby I have to search through 4-5 columns and produce the results with an order by according to the values matched in these columns. Example: My...
5
by: mabrynda | last post by:
Hi, Is there any possibility to sum all the values in many (say n) columns in a single table using VBA in access 2003? Say I have a table with 200 columns. Say the table name is TableCOUNT and the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.