This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Selecting uniquely one 'asset' in XSL
- From: "Vasu Chakkera" <vasucv at hotmail dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Thu, 25 Apr 2002 09:31:41 +0000
- Subject: Re: [xsl] Selecting uniquely one 'asset' in XSL
- Reply-to: xsl-list at lists dot mulberrytech dot com
i have added a root element( assets ) to ur xml elements and started
working..
here is it
<assets>
<asset>Oil</asset>
<asset>Oil</asset>
<asset>Diamonds</asset>
<asset>Diamonds</asset>
</assets>
for this the xsl that would give u unique elements..
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="assets/asset"/>
</xsl:template>
<xsl:template match="asset">
<xsl:if test="not(. = preceding-sibling::asset)">
<xsl:value-of select="."/>.
</xsl:if>
</xsl:template>
</xsl:stylesheet>
or a BETTER Approach is
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="assets" match="asset" use="text()"/>
<xsl:template match="assets">
<xsl:apply-templates select="asset[count( . | key('assets',.)[1]) =1]"/>
</xsl:template>
</xsl:stylesheet>
--------------
>From: "Craig Aranjo" <aranjo@purplefinder.com>
>Reply-To: xsl-list@lists.mulberrytech.com
>To: <XSL-List@lists.mulberrytech.com>
>Subject: [xsl] Selecting uniquely one 'asset' in XSL
>Date: Thu, 25 Apr 2002 09:40:06 +0100
>
>
>This seems an a trivial problem but I just can't seem to get my head around
>it. I want to be able to select one unique 'asset' name from multiple
>assets
>(there are more than 1 asset of the same type) from XML document and
>display
>this in (say) a HTML table. Further entries of the same asset also need to
>appear except that the table entry for the asset name will be blank for the
>remainder assets.
>
>The XML document looks something like this:
>
><asset>Oil</asset>
>.
><asset>Oil</asset>
>.
><asset>Diamonds</asset>
>.
><asset>Diamonds</asset>
>
>Here are two attempts of mine when creating the XSL stylesheet:
>
>1:
>
><xsl:for-each select="parent::asset">
><xsl:if test="position() = 1">
><xsl:apply-templates selectparent::asset"/>
></xsl:if>
></xsl:for-each>
>
>
>2.
>
><xsl:variable name="assetname"
>select="//asset-name[not(.=preceding::asset-name)]"/>
><xsl:apply-templates select="$assetname"/>
>
>
>Neither of these achieve the desired result. Could someone please point me
>in the right direction.
>
>regards,
>Craig
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list