0

I'm trying to work out a way that several items in a list could be summarized in a single item if they have a keyword in common. For example, given the items:

Sounds: a
Sounds: b
Vocab: word
Vocab: foo
Vocab: bar
Sounds: a

I would return the values:

Sounds: a, b
Vocab: word, foo, bar

I have it as far as filtering out the non-unique items using

<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[not(@Skill=preceding-sibling::Row/@Skill)]">

But I'm a bit at sea when it comes to xslt node stuff. Any help or pointers would be appreciated.

0

OK I came up with a solution. It's kludgy but it works:

                        <xsl:template name="dvt_1">
                        <xsl:variable name="dvt_StyleName">Table</xsl:variable>
                        <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[(not(@Title=preceding-sibling::Row/@Title)) and not(contains(@Title,'Sound')) and not(contains(@Title,'Vocab'))]"/>
                        <xsl:variable name="Sounds" select="/dsQueryResponse/Rows/Row[contains(@Title,'Sound') and not(@Title=preceding-sibling::Row/@Title)]"/>
                        <xsl:variable name="Vocab" select="/dsQueryResponse/Rows/Row[contains(@Title,'Vocab') and not(@Title=preceding-sibling::Row/@Title)]"/>
                        <xsl:variable name="soundCount" select="count($Sounds)"/>
                        <xsl:variable name="vocabCount" select="count($Vocab)"/>
                        <xsl:variable name="dvt_RowCount" select="count($Rows)"/>
                        <xsl:variable name="RowLimit" select="10" />
                        <xsl:variable name="FirstRow" select="$dvt_firstrow" />
                        <xsl:variable name="LastRow" select="$FirstRow + $dvt_RowCount - 1" />
                        <xsl:variable name="IsEmpty" select="($dvt_RowCount = 0) and ($soundCount = 0) and ($vocabCount = 0)" />
                        <xsl:variable name="dvt_IsEmpty" select="($dvt_RowCount = 0) and ($soundCount = 0) and ($vocabCount = 0)"/>

                        <xsl:choose>
                            <xsl:when test="$dvt_IsEmpty">
                                <xsl:call-template name="dvt_1.empty"/>
        </xsl:when>
                            <xsl:otherwise>
            <table border="0" width="100%" cellpadding="2" cellspacing="0">
                <tr valign="top">
                    <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
                        <th class="ms-vh" width="1%" nowrap="nowrap"></th>
                    </xsl:if>
                    <th class="ms-vh" nowrap="nowrap">Title</th>
                </tr>
                <xsl:call-template name="dvt_1.body">
                    <xsl:with-param name="Rows" select="$Rows"/>
                    <xsl:with-param name="Sounds" select="$Sounds"/>
                    <xsl:with-param name="soundCount" select="$soundCount"/>
                    <xsl:with-param name="Vocab" select="$Vocab"/>
                    <xsl:with-param name="vocabCount" select="$vocabCount"/>                    
                    <xsl:with-param name="FirstRow" select="1" />
                    <xsl:with-param name="LastRow" select="$dvt_RowCount" />

                </xsl:call-template>
            </table>
        </xsl:otherwise>
                        </xsl:choose>
                        <xsl:call-template name="dvt_1.commandfooter">
                            <xsl:with-param name="FirstRow" select="$FirstRow" />
                            <xsl:with-param name="LastRow" select="$LastRow" />
                            <xsl:with-param name="RowLimit" select="$RowLimit" />
                            <xsl:with-param name="dvt_RowCount" select="$dvt_RowCount" />
                            <xsl:with-param name="RealLastRow" select="number(ddwrt:NameChanged('',-100))" />
                        </xsl:call-template>
                    </xsl:template>
                    <xsl:template name="dvt_1.body">
                        <xsl:param name="Rows"/>
                        <xsl:param name="FirstRow" />
                        <xsl:param name="LastRow" />
                        <xsl:param name="Sounds" />
                        <xsl:param name="soundCount" />
                        <xsl:param name="Vocab" />
                        <xsl:param name="vocabCount" />

                        <xsl:for-each select="$Rows">
                            <xsl:variable name="dvt_KeepItemsTogether" select="false()" />
                            <xsl:variable name="dvt_HideGroupDetail" select="false()" />
                            <xsl:if test="(position() &gt;= $FirstRow and position() &lt;= $LastRow) or $dvt_KeepItemsTogether">
                                <xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1">
                                    <xsl:call-template name="dvt_1.rowview" />
                                </xsl:if>
                            </xsl:if>

                         </xsl:for-each>
                            <!--Using variables so I can push the value to something else later!-->
                            <xsl:variable name="soundgroup">
                            Sounds:
                        <xsl:for-each select="$Sounds">
                            <xsl:call-template name="soundView" />
                            <xsl:if test="position() &lt; $soundCount">, </xsl:if>
                        </xsl:for-each> 
                        </xsl:variable>
                        <xsl:variable name="vocabgroup">
                            vocab:
                        <xsl:for-each select="$Vocab">
                            <xsl:call-template name="vocabView" />
                            <xsl:if test="position() &lt; $vocabCount">, </xsl:if>
                        </xsl:for-each> 
                        </xsl:variable>
                        <tr><td>

As it stands, I need to hard code all the keywords that I want to summarize on - like I said kludgy. I feel like there is a more elegant solution to this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.