xml - XSLT 1 Distinct grouping -
i'm trying distinct after grouping , doesn't work. using node :
<main> <value>a</value> <value>b</value> <value>ab</value> <value>a</value> <value>ab</value> </main>
i can use following xpath :
main/value[not(following::value/text() = text())]
and have distinct values b, ab, a. if have following node :
<main> <bloc> <typ>1</typ> <value>a</value> </bloc> <bloc> <typ>1</typ> <value>ba</value> </bloc> <bloc> <typ>1</typ> <value>b</value> </bloc> <bloc> <typ>1</typ> <value>a</value> </bloc> <bloc> <typ>2</typ> <value>a</value> </bloc> <bloc> <typ>2</typ> <value>c</value> </bloc> </main>
i'm trying group typ before doing distinct :
main/bloc[typ=1]/value[not(following::value/text() = text())]
it doesn't work, have ba , b without a.
if try :
main/bloc[typ=1]/value
the group return values of typ.
why distinct doesn't work after grouping ?
you need include check on typ=1
in check on following node too. @ moment, second "a" not being picked because have following node of "a"
main/bloc[typ=1]/value[not(following::bloc[typ=1]/value/text() = text())]
i note have tagged xslt, , mentioned xslt in title. in case should using technique called muenchian grouping distinct items.
first, define key so
<xsl:key name="blocs_by_value" match="bloc" use="value" />
then, distinct value nodes, this
<xsl:value-of select="main/bloc[generate-id() = generate-id(key('blocs_by_value', value)[1])]/value" />
for case want distinct value nodes specific type, define key so
<xsl:key name="blocs_by_typ_value" match="bloc" use="concat(typ, '|', value)" />
then, expression distinct values this...
<xsl:value-of select="main/bloc[typ=1][generate-id() = generate-id(key('blocs_by_typ_value', concat(typ, '|', value))[1])]/value" />
Comments
Post a Comment