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

Re: Splitting an element into two different places whi

Subject: Re: Splitting an element into two different places while merging in another
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 15 Oct 2002 15:47:46 +0100
splitting an element xslt
Hi Richard,

> 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.

Usually when that kind of thing occurs it's because you're generating
the elements that you're getting too many of at the wrong 'level' in
the stylesheet. In this case, you're generating them within a template
that matches each military_legal_assessments and each arrest_records
element in your document, so you get one legal_assessments element for
each -- 2 in total.

Instead, you should generate the legal_assessments element in a
template that matches on an element that only occurs once in the
stylesheet, such as the client element. Personally, I'd use a couple
of modes so that you can process the same military_legal_assessment in
two different ways -- once to produce a legal_assessment, and once to
produce a military_assessment:

<xsl:template match="client">
  <client>
    <legal_assessments>
      <xsl:apply-templates select="military_legal_assessments |
                                   arrest_records"
                           mode="legal_assessment" />
    </legal_assessments>
    <military_assessments>
      <xsl:apply-templates select="military_legal_assessments"
                           mode="military_assessment" />
    </military_assessments>
  </client>
</xsl:template>

<xsl:template match="military_legal_assessment | arrest_record"
              mode="legal_assessment">
  <legal_assessment>
    <xsl:copy-of select="@*" />
    <xsl:copy-of
      select="node()[name() = $legal_assessment_fields]" />
  </legal_assessment>
</xsl:template>

<xsl:template match="military_legal_assessment"
              mode="military_assessment">
  <military_assessment>
    <xsl:copy-of select="@*" />
    <xsl:copy-of
      select="node()[not(name() = $legal_assessment_fields)]
  </military_assessment>
</xsl:template>

(Note that this stylesheet relies on the built-in templates to process
each military_legal_assessments element by processing its contents,
and similarly for the arrest_records element.)

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.