xml - List unique values of an attribute within a group only for specific criteria in XSL 1.0 -


i need list unique values of attribute in group, when attribute has specific value. making work in xsl 1.0 tricky understand.

thanks post, have groupings defined allow me perform counts when attributes match specific criteria. i'm stumped on being able list unique values 1 specific attribute, attribute equal specific value, within members of current group.

as always, make more sense example source data , code.

here sample xml

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <group1>   <group2>     <locationidentification locationid="0610390" />     <locationidentification1 locationqualifier="12" locationid="uslgb"/>   </group2>   <group2>     <locationidentification locationid="0610612" />     <locationidentification1 locationqualifier="12" locationid="uslax"/>   </group2>   <group2>     <locationidentification locationid="0650004"/>     <locationidentification1 locationqualifier="12" locationid="uslgb"/>   </group2>   <group2>     <locationidentification locationid="0650306"/>     <locationidentification1 locationqualifier="6" locationid="uslax"/>    </group2>    <group2>     <locationidentification locationid="0650220"/>     <locationidentification1 locationqualifier="12" locationid="uslgb"/>    </group2> </group1> 

i have xsl set create groups based on first 3 characters of attribute locationid locationidentification node.

xsl 1.0

<xsl:stylesheet version="1.0"  <xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="html"/>  <xsl:key name="grp" match="group2" use="substring(locationidentification/@locationid, 1, 3)"/>  <xsl:template match="/group1"> <table align="center" border="1">     <thead>         <tr>             <th>bay</th>             <th>units</th>             <th>locations</th>         </tr>     </thead>     <tbody>         <xsl:for-each select="group2[generate-id()=generate-id(key('grp', substring(locationidentification/@locationid, 1, 3))[1])]">             <xsl:sort select="locationidentification/@locationid"/>             <xsl:variable name="curr-key" select="substring(locationidentification/@locationid, 1, 3)" />                        <xsl:variable name="curr-group" select="key('grp', $curr-key)" />             <tr>                 <td>                     <xsl:value-of select="$curr-key"/>                 </td>                 <td>                     <xsl:value-of select="count($curr-group)"/>                 </td>                 <td>                 <!-- new code needs go here -->                 </td>             </tr>         </xsl:for-each>     </tbody> </table> </xsl:template>  </xsl:stylesheet> 

what need figure out, how list unique values of locationid within locationidentification1 locationqualifier='12'

desired output

<table align="center" border="1">   <thead>     <tr>         <th>bay</th>         <th>count</th>         <th>location(s)</th>     </tr>   </thead>   <tbody>    <tr>     <td>061</td>     <td>2</td>     <td>uslgb uslax</td>   </tr>   <tr>     <td>065</td>     <td>3</td>     <td>uslgb</td>   </tr> </table> 

notice bay 65 has count of 3, 2 of members have locationqualifier of 12, , both have same value locationid, hence output should list uslgb location(s).

you need round of muenchian grouping:

xslt 1.0

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="html"/>  <xsl:key name="grp" match="group2" use="substring(locationidentification/@locationid, 1, 3)"/> <xsl:key name="loc12" match="locationidentification1[@locationqualifier='12']" use="concat(substring(../locationidentification/@locationid, 1, 3), '|', @locationid)"/>  <xsl:template match="/group1">     <table align="center" border="1">         <thead>             <tr>                 <th>bay</th>                 <th>units</th>                 <th>locations</th>             </tr>         </thead>         <tbody>             <xsl:for-each select="group2[generate-id()=generate-id(key('grp', substring(locationidentification/@locationid, 1, 3))[1])]">                 <xsl:sort select="locationidentification/@locationid"/>                 <xsl:variable name="curr-key" select="substring(locationidentification/@locationid, 1, 3)" />                            <xsl:variable name="curr-group" select="key('grp', $curr-key)" />                 <tr>                     <td>                         <xsl:value-of select="$curr-key"/>                     </td>                     <td>                         <xsl:value-of select="count($curr-group)"/>                     </td>                     <td>                         <xsl:for-each select="$curr-group/locationidentification1[@locationqualifier='12'][generate-id()=generate-id(key('loc12', concat($curr-key, '|', @locationid))[1])]">                             <xsl:value-of select="@locationid"/>                             <xsl:text> </xsl:text>                         </xsl:for-each>                     </td>                 </tr>             </xsl:for-each>         </tbody>     </table> </xsl:template>  </xsl:stylesheet> 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -