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

Re: Unique list of elements based in attribute

Subject: Re: Unique list of elements based in attribute
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 7 Mar 2007 20:56:30 GMT
Re:  Unique list of elements based in attribute
you havent said what output ypu wanted or what your stylesheet did wrong
but it has several lines that look strange 


<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <Category_List>
            <xsl:apply-templates select="category_list"/>
        </Category_List>
    </xsl:template>
    <!-- Any occurrence of category element in current context is applied -->
    <xsl:template match="category">
        <!-- check whether, category with same id is already processed or not -->
        <!-- Here I am trying to find any sibling categories with same id or not.-->
        <xsl:if test ="not($id=preceding-sibling::category/@id)">

You have not defined a variable $id, perhaps you meant @id.
You really want to group all elements with teh same ID in which case
google for xslt grouping, the xslt faq and jeni tennisons's site both
have many examples of this.

        
        <!--xsl:if test="@id!=ancestor::category/@id"-->

This is commented out, but beware never use != unless you are sure you
really mean that (and even then, use not(!=) instead.
@id != ancestor::category/@id
is true if the current id is not equal to any id on an ancestor, so that
will always be true if there is more then one id in the ancestor list.
I suspect you wanted
not(@id = ancestor::category/@id)
which is true if the current id is not equal to the id of an ancestor.

            <Category xmlns:YMIA="urn:schemas-music-yamaha-com:ymia">
Did you mean a capital C here rather than teh lower case name used elsewhere?
                <xsl:attribute name="Id">
                    <xsl:value-of select="@id"/>
            </xsl:attribute>
            </Category>

the above could more easily be written

            <Category xmlns:YMIA="urn:schemas-music-yamaha-com:ymia"
            id="{@id}"/>

        </xsl:if>
        <!-- Selects category list of current category. XSLT logic no worry :)  -->
        <xsl:apply-templates select="category_list"/>
    </xsl:template>




<xsl:if test ="not($id=preceding-sibling::category/@id)"> : This does not seem to work. Any input.
as noted above there is no variable with name id defined.

David

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.