Match attribute values (columns) to column names

Discussion in 'XML' started by Carl, Apr 4, 2004.

  1. Carl

    Carl Guest

    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>
    Carl, Apr 4, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carl
    Replies:
    0
    Views:
    515
  2. patrin
    Replies:
    5
    Views:
    895
    Dimitre Novatchev
    Sep 2, 2006
  3. Replies:
    3
    Views:
    1,526
    Brandon McCombs
    May 2, 2007
  4. news.microsoft.com

    hiding columns in gird based on column values

    news.microsoft.com, Oct 25, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    324
    Mark Rae [MVP]
    Oct 25, 2007
  5. mavrick_101
    Replies:
    3
    Views:
    1,547
    mavrick_101
    Feb 25, 2010
Loading...

Share This Page