xsl-list
[Top] [All Lists]

RE: [xsl] Grouping with keys

2013-10-24 14:01:26
At 2013-10-24 14:50 -0400, Rick Quatro wrote:
Here is a simplified example:

With the simplified example, the solution jumps out at me. I hope this helps and you can refine it into what you need. I think you were looking too deep.

. . . . . . . Ken

t:\ftemp>type rick.xml
<body>
  <li>one</li>
  <li>two</li>
  <p>paragraph</p>
  <li>three</li>
  <li>four</li>
  <p>paragraph</p>
  <li>five</li>
  <li>six</li>
</body>
t:\ftemp>call xslt rick.xml rick.xsl
<?xml version="1.0" encoding="utf-8"?>
<body>
   <ol>
      <li>one</li>
      <li>two</li>
   </ol>
   <p>paragraph</p>
   <ol>
      <li>three</li>
      <li>four</li>
   </ol>
   <p>paragraph</p>
   <ol>
      <li>five</li>
      <li>six</li>
   </ol>
</body>
t:\ftemp>type rick.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0">

<xsl:key name="li"
         match="li"
         use="generate-id((..|preceding-sibling::p[1])[last()])"/>

<xsl:output indent="yes"/>

<xsl:template match="body">
  <body>
    <xsl:for-each select=".|p">
      <xsl:copy-of select="self::p"/>
      <xsl:if test="key('li',generate-id(.))">
        <ol>
          <xsl:copy-of select="key('li',generate-id(.))"/>
        </ol>
      </xsl:if>
    </xsl:for-each>
  </body>
</xsl:template>

</xsl:stylesheet>
t:\ftemp>rem Done!


--
Public XSLT, XSL-FO, UBL & code list classes: Melbourne, AU May 2014 |
Contact us for world-wide XML consulting and instructor-led training |
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm |
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/ |
G. Ken Holman                   mailto:gkholman(_at_)CraneSoftwrights(_dot_)com 
|
Google+ profile: https://plus.google.com/116832879756988317389/about |
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>