I think the problem is due to the nodes you are applying the distinct() against. You are applying the 'sager' template against the '$sager/bynavn' - which wont process that. I've modified your XSLT, see if this works:
I thought it best to test this out... and I can't seem to get the 'distinct()' function to work! :-(
I keep getting the following exception (via the "umbDebugShowTrace=true" querystring)
umbracoMacro InnerException Value cannot be null.
Parameter name: type
Value cannot be null.
Parameter name: type
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at umbraco.presentation.xslt.Exslt.ExsltCommon.ExsltNodeListToXPathNodeIterator(ExsltNodeList list)
I've tried various ways of passing the node-set, (and different XML sources too), but nothing works.
Hmmm... could be a bug in the eXSLT implementation? or am I doing something wrong?
Personally I've used the "Muenchian" method several times, works well, but takes a little time to understand how it works; with key indexes and generate-id().
@Lee - For what it's worth, your example works as expected with xsltproc on my Mac, so I'm guessing a bug in the EXSLT.NET (or what it's called) implementation...
distinct values using Exslt.ExsltSets:distinct
Hi, can anyone help selecting distinct values from the node 'bynavn' in the following xml :
<?xml version="1.0" encoding="ISO-8859-1"?> <sager> <sag sagstype="1" status="aktiv"> <postnr>5909</postnr> <bynavn>Holbæk</bynavn> </sag> <sag sagstype="1" status="aktiv"> <postnr>1200</postnr> <bynavn>valby</bynavn> </sag> <sag sagstype="1" status="aktiv"> <postnr>1408</postnr> <bynavn>valby</bynavn> </sag> </sager>Here is my xslt so far, it just displays the nodes text as one text string.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:ontranet="urn:ontranet" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ontranet "> <xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:param name="currentPage"/> <xsl:template match="/"> <xsl:variable name="url" select="'http://data.notar.dk.nt11.unoeuro.com/husavisen.xml'"/> <xsl:variable name="pagexml" select="umbraco.library:GetXmlDocumentByUrl($url)" /> <xsl:variable name="sager" select="$pagexml/sager/sag" /> <xsl:apply-templates select="$sager/bynavn" /> </xsl:template> <xsl:template match="sager"> <xsl:for-each select="Exslt.ExsltSets:distinct(bynavn)"> <xsl:value-of select="."/> <br/> </xsl:for-each> </xsl:template> </xsl:stylesheet>Hi Peter,
I think the problem is due to the nodes you are applying the distinct() against. You are applying the 'sager' template against the '$sager/bynavn' - which wont process that. I've modified your XSLT, see if this works:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:ontranet="urn:ontranet" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ontranet "> <xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:param name="currentPage"/> <xsl:template match="/"> <xsl:variable name="url" select="'http://data.notar.dk.nt11.unoeuro.com/husavisen.xml'"/> <xsl:variable name="pagexml" select="umbraco.library:GetXmlDocumentByUrl($url)" /> <xsl:variable name="sager" select="$pagexml/sager/sag" /> <xsl:apply-templates select="Exslt.ExsltSets:distinct($sager/bynavn)" /> </xsl:template> <xsl:template match="bynavn"> <xsl:value-of select="text()"/> <br /> </xsl:template> </xsl:stylesheet>Now we apply the 'bynavn' template against the distinct node-set, rather than trying to do that per 'sag' item.
Hope this makes sense?
Cheers, Lee.
I thought it best to test this out... and I can't seem to get the 'distinct()' function to work! :-(
I keep getting the following exception (via the "umbDebugShowTrace=true" querystring)
I've tried various ways of passing the node-set, (and different XML sources too), but nothing works.
Hmmm... could be a bug in the eXSLT implementation? or am I doing something wrong?
Anyone got any ideas?
Cheers, Lee.
Peter, in the meantime, take a look at this other forum thread for an alternative approach:
http://our.umbraco.org/forum/developers/xslt/4482-xslt-distinct
Personally I've used the "Muenchian" method several times, works well, but takes a little time to understand how it works; with key indexes and generate-id().
Good luck, Lee.
@Lee - For what it's worth, your example works as expected with xsltproc on my Mac, so I'm guessing a bug in the EXSLT.NET (or what it's called) implementation...
/Chriztian
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.