xsl-list
[Top] [All Lists]

[xsl] Unique list of elements based in attribute

2007-03-07 13:00:24
Hi Group,
            I am trying to generate stylesheet that would produce elements with 
unique attribute value.

My xml:
<category_list>
    <category id="16277" sort_order="10">
        <label language="en">Pianos and  keyboard instruments</label>
        <category_list>
            <category id="16170" sort_order="10">
                <label language="en">Grand pianos</label>
                    <category_list>
                    <category id="16323" sort_order="10">
                        <label language="en">Silent unit</label>
                     </category>
                    </category_list>
                </category>
    <category id="16377" sort_order="10">

        <label language="en">Pianos and  keyboard instruments</label>

        <category_list>

            <category id="16277" sort_order="10">

                <label language="en">Grand pianos</label>

                    <category_list>

                    <category id="16323" sort_order="10">

                        <label language="en">Silent unit</label>

                     </category>

                    </category_list>

                </category>
        </category_list>
....
.....

Stylesheet:

<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)">
        
        <!--xsl:if test="@id!=ancestor::category/@id"-->
            <Category xmlns:YMIA="urn:schemas-music-yamaha-com:ymia">
                <xsl:attribute name="Id">
                    <xsl:value-of select="@id"/>
            </xsl:attribute>
            </Cat
/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.

-R




 
____________________________________________________________________________________
Finding fabulous fares is fun.  
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel 
bargains.
http://farechase.yahoo.com/promo-generic-14795097

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>