 |
 |
 |
On Mar 31, 11:17 am, Martin Honnen <mahotr...@yahoo.de> wrote:
> WideBoy wrote:
> > I would like to sort and unique a list of elements that I extract from
> > an XMI file.
> > My xslt script successfully sorts the data but I need help in creating
> > a unique list.
>
> > A fragment of my xslt looks like this:
> > ...
> > <xsl:template name="ExtractDTs">
> > <xsl:for-each select="/XMI/XMI.content/UML:Model/
> > UML:Namespace.ownedElement/UML:DataType/@name">
> > <xsl:sort data-type="text" order="ascending"/>
> > <xsl:choose>
> > <xsl:when test="fn:ends-with(.,'Amount')">
>
> ends-with suggests you are using XSLT 2.0 so there you have
> xsl:for-each-group <URL:http://www.w3.org/TR/xslt20/#xsl-for-each-group>
> as an instruction and the function distinct-values
> <URL:http://www.w3.org/TR/xpath-functions/#func-distinct-values> to help
> you to find unique values.
>
> Here is an example using distinct-values, assuming the XML input looks
> like this:
>
> <root>
> <item>1</item>
> <item>0</item>
> <item>5</item>
> <item>2</item>
> <item>1</item>
> <item>4</item>
> <item>0</item>
> </root>
>
> then this stylesheet
>
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="2.0">
>
> <xsl:output method="text"/>
>
> <xsl:template match="root">
> <xsl:for-each select="distinct-values(item)">
> <xsl:sort select="." data-type="number"/>
> <xsl:value-of select="."/>
> <xsl:text> </xsl:text>
> </xsl:for-each>
> </xsl:template>
>
> </xsl:stylesheet>
>
> outputs
>
> 0
> 1
> 2
> 4
> 5
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/
Martin,
Thank you very much for this neat solution.
Best regards,
Naran
|
 | 

|  |
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.
|  |
| |
 |
 |
 |