Search

I am creating this topic again as I am now unable to open the previous one. What would be the XSLT like to convert the following xml

<SearchResultsAddressDataSet xmlns="http://tempuri.org/SearchResultsAddressDataSet.xsd">
<AddressResults><ID>10</ID><Country>Aruba</Country><PostalCode>CA 94555-3658</PostalCode><Deleted>N</Deleted><lAddressLines>test text xyz</lAddressLines></AddressResults>
<AddressResults><ID>10</ID><Country>Aruba</Country><PostalCode>CA 94555-3658</PostalCode><Deleted>N</Deleted><lAddressLines>test temp</lAddressLines></AddressResults>
<AddressResults><ID>10</ID><Country>Aruba</Country><PostalCode>CA 94555-3658</PostalCode><Deleted>N</Deleted><lAddressLines>test3 gtrgtrrthyty</lAddressLines></AddressResults>
<AddressResults><ID>11</ID><Country>UK</Country><PostalCode>CA 9fd5-3658</PostalCode><Deleted>N</Deleted><lAddressLines>test</lAddressLines></AddressResults></SearchResultsAddressDataSet>

to the following xml

<SearchResultsAddressDataSet xmlns="http://tempuri.org/SearchResultsAddressDataSet.xsd">
<AddressResults><ID>10</ID><Country>Aruba</Country><PostalCode>CA 94555-3658</PostalCode><Deleted>N</Deleted><lAddressLines>test text xyz,test temp,test3 gtrgtrrthyty</lAddressLines></AddressResults>
<AddressResults><ID>11</ID><Country>UK</Country><PostalCode>CA 9fd5-3658</PostalCode><Deleted>N</Deleted><lAddressLines>test</lAddressLines></AddressResults></SearchResultsAddressDataSet>

i.e. address lines have been comma separated and in one record only.

Thanks

Is this a Symphony project? It sounds to me like a .Net project.

@Urvashi - You’ll want to use the Muenchian Method of Grouping. Use Jeni Tennison’s site, http://jenitennison.com/xslt/grouping/ to learn more about it.

@bzerangue - Thanks for the link it is quiet useful. @designermonkey - No it is not a Symphony project.

I tried the following xslt based on the jenitennison link but it doesn’t seem to be working. Can anybody help?

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="rows" match="AddressResults" use="ID" />
<xsl:template match="SearchResultsAddressDataSet">
  <xsl:apply-templates
    select="AddressResults[generate-id(.) = generate-id(key('rows', ID)[1])]" />
</xsl:template>
<xsl:template match="AddressResults">
  <b><xsl:value-of select="ID" /></b>
 <AddressResults><ID><xsl:value-of select="ID" /></ID>
<Country><xsl:value-of select="Country" />
</Country>
<PostalCode><xsl:value-of select="PostalCode" />
</PostalCode><Deleted><xsl:value-of select="Deleted" />
</Deleted><lAddressLines>
     <xsl:for-each select="key('rows', ID)">
        <xsl:value-of select="lAddressLines" />,

     </xsl:for-each>
</lAddressLines>
</AddressResults>
</xsl:template>
</xsl:stylesheet>

Thanks in advance

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details