|
Subject: [xsl] Unique list of elements based in attribute From: Tech Guru <tech_gr@xxxxxxxxx> Date: Wed, 7 Mar 2007 11:59:57 -0800 (PST) |
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>
</Category>
</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
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] Key to select all same no, Michael Kay | Thread | Re: [xsl] Unique list of elements b, David Carlisle |
| Re: [xsl] inline within block withi, J.Pietschmann | Date | Re: [xsl] inline within block withi, John Cavalieri |
| Month |