Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8106287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:25:24+00:00 2026-06-06T00:25:24+00:00

I posted a question about keys yesterday, and got very helpful responses. I’ve been

  • 0

I posted a question about keys yesterday, and got very helpful responses. I’ve been working on the last detail in this particular file set most of today; there must just be something I’m missing when it comes to the proper use of keys.

I have the following definition list:

<dl>
<dlentry>
<dt>BLARG a</dt>
<dd>BLARG Definition b</dd>
</dlentry>
<dlentry>
<dt outputclass="values">Value c<ph> Value Description d</ph></dt>
<dd/>
</dlentry>
<dlentry>
<dt outputclass="values">Value e<ph> Value Description f</ph></dt>
<dd/>
</dlentry>
<dlentry>
<dt outputclass="values">Value g<ph> Value Description h</ph></dt>
<dd/>
</dlentry>
<dlentry>
<dt>BLARG2 i</dt>
<dd>BLARG2 Description j</dd>
</dlentry>
<dlentry>
<dt outputclass="values">Value k
<ph>Value description l</ph></dt>
<dd/>
</dlentry>
<dlentry>
<dt outputclass="values">Value m
    <ph>Value description n</ph></dt>
<dd/>
</dlentry>
<dlentry>
    <dt outputclass="values">Value o
    <ph>Value description p</ph></dt>
<dd/>
</dlentry>
<dlentry><dt>BLARG3 q</dt>
<dd>BLARG3 Definition r</dd></dlentry>
</dl>

Here is my transformation (that doesn’t quite work — I had it closer than this earlier today, but managed to make it worse):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="kFollowing" match="dlentry[child::dt/@outputclass='values']" 
    use="generate-id(preceding-sibling::dlentry[not(child::dt/@outputclass='values')])"/>

<!-- identity template -->
<xsl:template match="@*|node()" name="identity">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="dd[../following-sibling::dlentry[1]/dt[@outputclass='values']]">
    <xsl:variable name="vFollowing" select="key('kFollowing',generate-id(..))"/>
    <dd><xsl:value-of select="."/>
        <table>
            <tgroup cols="2">
                <colspec colnum="1" colname="col1" colwidth="*"/>
                <colspec colnum="2" colname="col2" colwidth="*"/>
                <tbody>
                    <xsl:for-each select="../following-sibling::dlentry[key('kFollowing',$vFollowing)]">
                        <row>
                            <entry colname="1">
                                <xsl:value-of select="./dt/text()"/>
                            </entry>
                            <entry colname="2">
                                <xsl:apply-templates select="./dt/ph/text()"></xsl:apply-templates>
                            </entry>
                        </row>
                    </xsl:for-each>
                </tbody>
            </tgroup>
        </table></dd>
</xsl:template>
</xsl:stylesheet>

And my desired output:

<dl>
<dlentry>
    <dt>BLARG a</dt>
    <dd>BLARG Definition b
    <table>
        <tgroup cols="2">
            <colspec colnum="1" colname="col1" colwidth="*"/>
            <colspec colnum="2" colname="col2" colwidth="*"/>
            <tbody>
                <row>
                    <entry colname="1">Value c</entry>
                    <entry colname="2">Value Description d</entry>
                </row>
                <row>
                    <entry colname="1">Value e</entry>
                    <entry colname="2">Value Description f</entry>
                </row>
                <row>
                    <entry colname="1">Value g</entry>
                    <entry colname="2">Value Description h</entry>
                </row>
            </tbody>
        </tgroup>
    </table></dd>
</dlentry>
<dlentry>
    <dt>BLARG2 i</dt>
    <dd>BLARG2 Definition j
        <table>
            <tgroup cols="2">
                <colspec colnum="1" colname="col1" colwidth="*"/>
                <colspec colnum="2" colname="col2" colwidth="*"/>
                <tbody>
                    <row>
                        <entry colname="1">Value k</entry>
                        <entry colname="2">Value Description l</entry>
                    </row>
                    <row>
                        <entry colname="1">Value m</entry>
                        <entry colname="2">Value Description n</entry>
                    </row>
                    <row>
                        <entry colname="1">Value o</entry>
                        <entry colname="2">Value Description p</entry>
                    </row>
                </tbody>
            </tgroup>
        </table></dd>
</dlentry>
<dlentry><dt>BLARG3 q</dt>
    <dd>BLARG3 Definition r<dd></dlentry>
</dl>

Grouping rules (Sean’s edit)

nodes are grouped on nodes which do NOT have a dt[outputclass=”values”] child, AND all following sibling nodes which DO have a dt[outputclass=”values”] child.

The transformation of nodes are thus grouped. Note that if the group has only one member in it (that is to say no dlentry s with a dt[outputclass=”values”], then the table output as shown in the sample output document is to be suppressed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:25:25+00:00Added an answer on June 6, 2026 at 12:25 am

    How about this …

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" />
    <xsl:strip-space elements="*"/>
    
    <xsl:key name="dl-group" match="dlentry[child::dt/@outputclass='values']" 
        use="generate-id( preceding-sibling::dlentry[ not( child::dt/@outputclass='values')][1])"/>
    
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="dlentry/dd">
     <xsl:variable name="head" select="generate-id(..)" />      
     <xsl:copy>
      <xsl:value-of select="." />
      <xsl:if test="count( key('dl-group',$head))"> 
       <xsl:text>&#x0A;</xsl:text>
       <table>
        <tgroup cols="2">
         <colspec colnum="1" colname="col1" colwidth="*"/>
         <colspec colnum="2" colname="col2" colwidth="*"/>
         <tbody>
          <xsl:for-each select="key('dl-group',$head)" >
           <row>
            <entry colname="1">
             <xsl:value-of select="normalize-space(./dt/text())" />
            </entry>
            <entry colname="2"><xsl:value-of select="./dt/ph/text()" /></entry>
           </row>
          </xsl:for-each>
         </tbody>
        </tgroup>
       </table>
      </xsl:if> 
     </xsl:copy>
    </xsl:template>
    
    <xsl:template match="dlentry[dt[@outputclass='values']]" />
    
    </xsl:stylesheet>
    

    Explanation

    This is just a straight forward application of keys. It looks like you were over-complicating things. Perhaps you were thinking of muenchian grouping. We put the id of the header dd node in a variable to save re-computation. To produce the rows, we simply iterate over the node set returned by the key() function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I posted this question about 15 minutes ago and I got some good responses.
Recently I posted a question about the html helper dropdownlist and got it working
Yesterday I posted this question about protecting files: Protecting the app sandbox As mentioned,
Yesterday I've posted question about SQLite performance issues ( Terrible performance in Zend Db
I have already posted a question about this, but the situation has changed sufficiently
So I just have posted a question about this code (which was answered): $(document).ready(Main);
I recently posted a question about getting last 3 results in table in the
I posted a question about this earlier, but I have more information now and
earlier i posted a question about cin skipping input, and I got results to
I already posted a question about this ( Abandoned instances that will not continue

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.