Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: distinct-values work-around for Xpath 1.0 >Thread Next - Re: distinct-values work-around for Xpath 1.0 Re: distinct-values work-around for Xpath 1.0To: NULL Date: 8/27/2009 5:11:00 AM On 27 Aug, 13:39, Martin Honnen <mahotr...@yahoo.de> wrote:
> Barnum wrote:
> > For me, this does not work because the nodes are in a variable, that I
> > selected from another node-set. And my <foo> nodes do not have a
> > common parent.
> > I did something like this: <xsl:variable name=3D"fie" select=3D"root/fo=
o
> > [..some predicate here....].
> > Maybe I can build a new node set with a root node with the _selected_
> > foos beneath? And then do the preceding-sibling trick?
>
> You will need to show the relevant XML and explain which nodes you are
> interested in, then we can hopefully sort it out.
>
> > The Muenchian approach is also difficult (impossible?) to apply,
> > because xsl:key is a top-level node only.
>
> xsk:key is a top level element but you can certainly specify a match
> pattern for nodes at any level. For instance
> =A0 =A0<xsl:key name=3D"k1" match=3D"foo[your predicate here]" match=3D".=
"/>
> is certainly possible to define the key only for 'foo' elements
> fulfilling your predicate.
>
> --
>
> =A0 =A0 =A0 =A0 Martin Honnen --- MVP XML
> =A0 =A0 =A0 =A0http://msmvps.com/blogs/martin_honnen/
Ok, here is what I have:
This is the XML input:
<root>
<foo @name=3D"1">a</foo>
<foo @name=3D"1">b</foo>
<foo @name=3D"1">a</foo>
<foo @name=3D"2">c</foo>
<foo @name=3D"2">c</foo>
<foo @name=3D"2">d</foo>
</root>
And here is what I would have done with distinct-values:
<?xml version=3D"1.0" encoding=3D"utf-8"?>
<xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl=3D"urn:schemas-microsoft-com:xslt" version=3D"1.0">
<!-- root template: -->
<xsl:template match=3D"/root">
<xsl:call-template name=3D"fum">
<xsl:with-param name=3D"in" select=3D"."/>
</xsl:call-template>
</xsl:template>
<!-- sub-template: -->
<xsl:template name=3D"fum">
<xsl:param name=3D"in"/>
<!-- this is the input -->
<xsl:variable name=3D"fie" select=3D"$in/foo[@name=3D'1']" />
<xsl:variable name=3D"fum" select=3D"distinct-values($fie)" />
</xsl:template>
</xsl:stylesheet>
I expect to get only these nodes in fum:
<foo @name=3D"1">a</foo>
<foo @name=3D"1">b</foo>
(As a by-note, xsl:key can't be in the xsl:template......)
Thanks very much!
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
