xsl-list
[Top] [All Lists]

Re: [xsl] grouping problem

2007-11-27 20:56:44
At 2007-11-28 02:42 +0000, tofner(_at_)comcast(_dot_)net wrote:
I could use some hints on using for-each group in 2.0 using Saxon8.

If I understand your question properly, then it isn't a "grouping problem" per se, that is, it doesn't need for-each-group.

I am sure that the problem is my stylesheet. Here is the input:
...
I am trying to group the name attribute of the <selection> elements with matching <item> selection attributes so that the <items> follow their <selection> elements.

You don't give an example, but I've got an answer below that has item elements following selection elements where the attributes correspond. I think that is what you are asking for.

Thanks in advance for any hints,

I hope the answer below suffices ... but it doesn't use any grouping functionality.

. . . . . . . . . Ken


T:\ftemp>type terry.xml
<test>
  <selection name="u1pt01">
    <para> text . . . </para>
  </selection>
  <selection name="u1pt02">
    <para> text . . . </para>
  </selection>
  <item id="1" selection="u1pt01">
    <text> text and more tags</text>
  </item>
  <item id="2" selection="u1pt01">
    <text> text and more tags</text>
  </item>
  <item id="3" selection="u1pt02">
    <text> text and more tags</text>
  </item>
</test>

T:\ftemp>type terry.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="2.0">

<xsl:output indent="yes"/>
<xsl:strip-space elements="test"/>

<!--collect corresponding items after each selection-->
<xsl:template match="selection">
  <xsl:copy-of select="."/>
  <xsl:copy-of select="../item[(_at_)selection=current()/@name]"/>
</xsl:template>

<!--ignore the item's original position-->
<xsl:template match="item"/>

<!--all other nodes are just copied-->
<xsl:template match="@*|node()"><!--identity for all other nodes-->
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>call xslt2 terry.xml terry.xsl terry.out

T:\ftemp>type terry.out
<?xml version="1.0" encoding="UTF-8"?>
<test>
   <selection name="u1pt01">
      <para> text . . . </para>
  </selection>
   <item id="1" selection="u1pt01">
      <text> text and more tags</text>
  </item>
   <item id="2" selection="u1pt01">
      <text> text and more tags</text>
  </item>
   <selection name="u1pt02">
      <para> text . . . </para>
  </selection>
   <item id="3" selection="u1pt02">
      <text> text and more tags</text>
  </item>
</test>
T:\ftemp>rem Done!





--
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(_at_)CraneSoftwrights(_dot_)com
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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>