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

Re: attribute values as name value pair

Subject: Re: attribute values as name value pair
From: "James A. Robinson" <jimr@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 26 Feb 2004 18:50:08 -0800
name value pair
Given a input xml of
	<input>
		<data>...</data>
		<table>...</table>
	</input>

Will this do what you want?  It's probably not the most efficent since I'm
doing n*n for-each loops... :(

<?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="./input/data"/>
        </data>
    </xsl:template>

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

    <xsl:template match="row">
        <xsl:variable name="row_attributes" select="@*"/>
        <xsl:variable name="column_count" select="position()"/>
        <xsl:for-each select="/input/table/columns/column">
            <xsl:variable name="row_name" select="@name"/>
            <xsl:element name="row">
                <xsl:attribute name="id">
                    <xsl:value-of select="position() * $column_count"/>
                </xsl:attribute>
                <xsl:attribute name="key">
                    <xsl:value-of select="@value"/>
                </xsl:attribute>
                <xsl:attribute name="value">
                    <xsl:for-each select="$row_attributes">
                        <xsl:if test="local-name(.) = $row_name">
                            <xsl:value-of select="."/>
                        </xsl:if>
                    </xsl:for-each>
                </xsl:attribute>
            </xsl:element>
        </xsl:for-each>
    </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.