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

Splitting an element into two different places while m

Subject: Splitting an element into two different places while merging inanother
From: Richard Rowell <richard@xxxxxxxxxxxxxxxxx>
Date: 15 Oct 2002 09:22:54 -0500
while m
I need to split a set of elements into two sets, while merging in
another set of elements. My XML input looks like so:

<client>
  ...
  <military_legal_assessments>
    <military_assessment date_added='2002-06-21T14:28:16'
date_updated="2002-08-02T10:11:55">
     <veteran>true</veteran>
     <current_warrant>true</current_warrant>
    </military_assessment>
   </military_legal_assessments>
   ...
   <arrest_records>
    <arrest_record date_added='2002-04-21T16:30:50'
date_updated="2002-09-23T09:26:45">
     <date_arrested>12/1/2001</date_arrested>
     <charge>What was the client arrested for (what charge)</charge>
     <place>Where did the arrest occur</place>
     <descrip>Details about the arrest</descrip>
    </arrest_record>
    ...
   </arrest_records>   
   ...
</client>

I need to split each military_legal_assesment into two assessments
(military_assessment and legal_assessment) and also dump the arrest
records as legal assessments.  So the above would transform into this:

<client>
 ...
 <legal_assessments>
  <legal_assessment date_added='2002-06-21T14:28:16'
date_updated="2002-08-02T10:11:55">
   <current_warrant>true</current_warrant>
  </legal_assessment>
  <legal_assessment date_added='2002-04-21T16:30:50'
date_updated="2002-09-23T09:26:45">
   <charge>What was the client arrested for (what charge)</charge>
   <place>Where did the arrest occur</place>
  </legal_assessment>
  ...
 </legal_assessments>
 <military_assessments>
  <military_assessment date_added='2002-06-21T14:28:16'
date_updated="2002-08-02T10:11:55">
   <veteran>true</veteran>      
  </military_assessment>
  ...
 </military_assessments>
</client>

I am stuck on how to correctly handle the arrest records.  Everything
seems to process OK but I get two legal_assessments elements where I
need/want/can only have one.  Here is my template and the corresponding
output (Note that there is a node-set variable named
$legal_assessment_fields that defines the names of all the elements that
need to go into the legal assessment):

  <xsl:template
match="client/military_legal_assessments|client/arrest_records">
   <xsl:if test="name()='military_legal_assessments'">
    <military_assessments>
     <xsl:for-each select="node()">
      <xsl:element name="military_assessment">
       <xsl:copy-of select="@*"/>
       <xsl:copy-of
select="node()[not(name()=$legal_assessment_fields)]"/>
      </xsl:element>
     </xsl:for-each>
    </military_assessments>
   </xsl:if>
   <legal_assessments>
    <xsl:for-each select="node()">
     <xsl:element name="legal_assessment">
      <xsl:copy-of select="@*"/>
      <xsl:copy-of select="node()[name()=$legal_assessment_fields]"/>
     </xsl:element>
    </xsl:for-each>
   </legal_assessments>

Here is the output, note the two legal_assessments elements
 <client>
  ...
      <military_assessments>
        <military_assessment date_added="2002-06-21T16:30:50"
        date_updated="2002-08-23T09:26:45">
          <veteran>true</veteran>
        </military_assessment>
	...
      </military_assessments>

      <legal_assessments>
        <legal_assessment date_added="2002-06-21T16:30:50"
        date_updated="2002-08-23T09:26:45">
          <current_warrant>true</current_warrant>
        </legal_assessment>
	...
      </legal_assessments>
	...
      <legal_assessments>
        <legal_assessment date_added="2002-04-21T16:30:50"
        date_updated="2002-09-23T09:26:45">
          <date_arrested>12/1/2001</date_arrested>
          <charge>What was the client arrested for (what
charge)</charge>
          <place>Where did the arrest occur</place>
          <descrip>Details about the arrest</descrip>
        </legal_assessment>
        ...
      </legal_assessments>
  ...
 </client>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.