[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Deepening a flat structure and numbering nodes

Subject: Re: Deepening a flat structure and numbering nodes
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 10 Aug 2013 12:06:19 -0400
Re:  Deepening a flat structure and numbering nodes
At 2013-08-10 08:53 -0400, Rick Quatro wrote:
I need to do something different to the
<DifferentialDiagnosis> elements. I want to change the element names by
numbering them sequentially within my <newRecord> element, like this:

<?xml version="1.0" encoding="UTF-8"?>
<data>
   <newRecord>
      <Category>Category</Category>
      <Subcategory>Subcategory</Subcategory>
      <Case>1</Case>
      <CaseTitle>Title One</CaseTitle>
      <Institution>Institution One</Institution>
      <Author>Authors One</Author>
      <History>History One</History>
      <DifferentialDiagnosis1>Sick</DifferentialDiagnosis1>
      <DifferentialDiagnosis2>Sicker</DifferentialDiagnosis2>
      <DifferentialDiagnosis3>Sickest</DifferentialDiagnosis3>
      <TeachingPoint>Point1</TeachingPoint>
      <TeachingPoint>Point2</TeachingPoint>
   </newRecord>
   <newRecord>
      <Category>Category One</Category>
      <Subcategory>Subcategory</Subcategory>
      <Case>2</Case>
      <CaseTitle>Title Two</CaseTitle>
      <Institution>Title Two</Institution>
      <Author>Author Two</Author>
      <History>History Two</History>
      <DifferentialDiagnosis1>Sick</DifferentialDiagnosis1>
      <DifferentialDiagnosis2>Sicker</DifferentialDiagnosis2>
      <DifferentialDiagnosis3>Sickest</DifferentialDiagnosis3>
<TeachingPoint>Point1</TeachingPoint>
      <TeachingPoint>Point2</TeachingPoint>
   </newRecord>
</data>

I added this rule to my stylesheet:

    <xsl:template match="DifferentialDiagnosis" mode="in-case-siblings">
        <xsl:variable name="diagnosis"><xsl:number
count="DifferentialDiagnosis" from="Category"/></xsl:variable>
        <xsl:element name="{concat(name(),$diagnosis)}"><xsl:value-of
select="."/></xsl:element>
        <xsl:apply-templates
            select="following-sibling::*[1][not(self::Category)]"
mode="in-case-siblings"/>
    </xsl:template>

This basically "works" except the numbers are sequential throughout the
document.

<data>
   <newRecord>
        ...
      <DifferentialDiagnosis1>Sick</DifferentialDiagnosis1>
      <DifferentialDiagnosis2>Sicker</DifferentialDiagnosis2>
      <DifferentialDiagnosis3>Sickest</DifferentialDiagnosis3>
        ...
   </newRecord>
   <newRecord>
        ...
      <DifferentialDiagnosis1>Sick</DifferentialDiagnosis5>
      <DifferentialDiagnosis2>Sicker</DifferentialDiagnosis6>
      <DifferentialDiagnosis3>Sickest</DifferentialDiagnosis7>
        ...
   </newRecord>
</data>

I need the numbers to reset for each <newRecord> element. I am sorry for the
long post, but I want to be complete as possible. Also, for this project, I
need to use XSLT 1.0.

Just count the difference of those from where you are less those that are before the closest group before:


<xsl:element name="concat(name(.),
1 + count(preceding-sibling::DifferentialDiagnosis)
- count(preceding-sibling::Category[1]/preceding-sibling::DifferentialDiagnosis))">


I hope this helps.

. . . . . . . . Ken

--
Public XSLT, XSL-FO, and UBL classes in the Netherlands     Oct 2013 |
Public XSLT, XSL-FO, UBL and code list classes in Australia Oct 2013 |
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@xxxxxxxxxxxxxxxxxxxx |
Google+ profile: https://plus.google.com/116832879756988317389/about |
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal |

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.