Re: [xsl] Re: attribute values as name value pair

Subject: Re: [xsl] Re: attribute values as name value pair
From: "James A. Robinson" <jimr@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 27 Feb 2004 00:34:57 -0800
Here's my second go at it. I just had to see if I could figure out a
way to count only the rows which matched our criteria.  Anyone see any
problems with it?  How would one test whether the following solution
is efficent or inefficent compared to the much shorter and to-the-point
example Sam posted?

<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="";>

    <xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/>

    <xsl:template match="/">
            <xsl:apply-templates select="//data/row/@*"/>

       Turn each row attribute into an element row with
       attributes id, key, and value.
    <xsl:template match="row/@*">
        <xsl:variable name="name" select="name()"/>
        <xsl:variable name="disp" select="//table/columns/column[@name=$name]/@value"/>
        <xsl:if test="$disp">
            <xsl:element name="row">
                <xsl:attribute name="id">
                    <xsl:call-template name="row_count">
                        <xsl:with-param name="rows" select="//data/row/@*"/>
                        <xsl:with-param name="id" select="generate-id(.)"/>
                        <xsl:with-param name="idx_count" select="1"/>
                        <xsl:with-param name="match_count" select="1"/>
                <xsl:attribute name="key">
                    <xsl:value-of select="$disp"/>
                <xsl:attribute name="value">
                    <xsl:value-of select="."/>

       count the number of $rows nodes which occur
       up to the node with a generate-id() matchin $id,
       and which have a name() equal to one in
    <xsl:template name="row_count">
        <xsl:param name="rows"/>
        <xsl:param name="id"/>
        <xsl:param name="idx_count"/>
        <xsl:param name="match_count"/>

        <xsl:variable name="new_idx_count" select="1+$idx_count"/>

        <xsl:variable name="name" select="name($rows[$idx_count])"/>
        <xsl:variable name="match" select="count(//table/columns/column[@name=$name])"/>

            <xsl:when test="generate-id($rows[$idx_count]) = $id">
                <xsl:value-of select="$match_count"/>
                <xsl:call-template name="row_count">
                    <xsl:with-param name="rows" select="$rows"/>
                    <xsl:with-param name="id" select="$id"/>
                    <xsl:with-param name="idx_count" select="$new_idx_count"/>
                    <xsl:with-param name="match_count" select="$match+$match_count"/>

 XSL-List info and archive:

Current Thread