Re: [xsl] Grouping repeating elements within repeating elements

Subject: Re: [xsl] Grouping repeating elements within repeating elements
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 09 Dec 2007 18:30:57 +0900
At 2007-12-06 02:42 -0600, Cynthia.Arangua@xxxxxxxxxxxxxx wrote:
Strike what I had asked for before.  I think I got that working.  But now,
I am running into another issue.

This code is basically building out an FAQ page.  But my problem really is
is that there are cases where there will be no headings (i.e. a parent
node).  If that is the case, I just need to display the questions and
answers and bypass wrapping in a div tag that the values from the headings
would produce.

I have it working now where if there are no headings, then just display the
questions and answers.  But unfourtunately, the xsl:if that I have in place
is getting stepped into even by questions and answers that do have headings
and they are showing up as duplicates.

The XML input below is still the same but the only variance is that I pull
in the content_category_faq value and pass that value into a query to pull
back all the XML objects that have value and thus display the questions and
answers.

I was unable to find how to feed the XML fragment from your earlier post into this transformation while extricating the query code.


The code is attached below and I have it commented where a more effective
if logic is needed.

I just can't seem to figure out how to get around the duplicate entries in
the questions and answers where there are indeed headings.

Thank you so much for any suggestions.

I feel it is important to point out the poor form in using disable-output-escaping= ... this construct is not used for synthesizing markup ... you should be using proper well-formed XML for all of your markup in your stylesheet. Here is an example where your code can be improved:


     <xsl:if test="string(heading[$index])">
      <xsl:text disable-output-escaping="yes"><![CDATA[<a class='linkMore'
      href='#' onclick="ContentHiearchy_FAQ(']]></xsl:text>
      <xsl:value-of select="$generatingHeaderId"/>
      <xsl:text disable-output-escaping="yes"><![CDATA[')">]]></xsl:text>
      <xsl:value-of select="concat($indent,heading[$index])"/>
      <xsl:text disable-output-escaping="yes"><![CDATA[</a><br/> <DIV
      id="]]></xsl:text>
      <xsl:value-of select="$generatingHeaderId"/>
      <xsl:text disable-output-escaping="yes"><![CDATA["
      class="content_hiearchy_hidden">]]></xsl:text>
      <!--determine if there is any information at the next level of
      depth-->
      <xsl:call-template name="next-heading">
       <xsl:with-param name="index" select="$index + 1"/>
       <xsl:with-param name="indent"
       select="concat($indent,'&#160;&#160;&#160;')"/>
       <xsl:with-param name="faqs" select="$faqs[heading[$index]=

current()/heading[$index]]"/>

      </xsl:call-template>
      <xsl:text disable-output-escaping="yes"><![CDATA[</div>]]></xsl:text>
     </xsl:if>

The above should be written as follows, using attribute value templates, so that all of the constructs in the stylesheet are element nodes and not unescaped text nodes:


     <xsl:if test="string(heading[$index])">
      <a class='linkMore' href='#'
         onclick="ContentHiearchy_FAQ('{$generatingHeaderId}')">
        <xsl:value-of select="concat($indent,heading[$index])"/>
      </a><br/>
      <div id="{$generatingHeaderId}" class="content_hiearchy_hidden">
       <!--determine if there is any information at the next level of
           depth-->
       <xsl:call-template name="next-heading">
        <xsl:with-param name="index" select="$index + 1"/>
        <xsl:with-param name="indent"
         select="concat($indent,'&#160;&#160;&#160;')"/>
        <xsl:with-param name="faqs" select="$faqs[heading[$index]=
                                                  current()/heading[$index]]"/>

       </xsl:call-template>
      </div>
     </xsl:if>

You should never be using disable-output-escaping= for "building tags" ... XSLT doesn't work with tags, it works with nodes created from the syntactic tags.

If you convert your stylesheet to one that works with an XML input file, then perhaps someone on the list will be able to help by running it and analyzing what is happening.

I hope this helps.

. . . . . . . . . . . . . Ken

--
Comprehensive in-depth XSLT2/XSL-FO1.1 classes: Austin TX,Jan-2008
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread