[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re: attribute values as name value pair

Subject: Re: Re: attribute values as name value pair
From: "James A. Robinson" <jimr@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 27 Feb 2004 00:34:57 -0800
xsl attribute name value
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="http://www.w3.org/1999/XSL/Transform">

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

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

    <!--
       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:call-template>
                </xsl:attribute>
                <xsl:attribute name="key">
                    <xsl:value-of select="$disp"/>
                </xsl:attribute>
                <xsl:attribute name="value">
                    <xsl:value-of select="."/>
                </xsl:attribute>
            </xsl:element>
        </xsl:if>
    </xsl:template>

    <!--
       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
       /table/columns/column/@name
    -->
    <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:choose>
            <xsl:when test="generate-id($rows[$idx_count]) = $id">
                <xsl:value-of select="$match_count"/>
            </xsl:when>
            <xsl:otherwise>
                <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:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.