Re: [xsl] Splitting an element into two different places while merging in another

Subject: Re: [xsl] 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
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">
      <xsl:apply-templates select="military_legal_assessments |
                           mode="legal_assessment" />
      <xsl:apply-templates select="military_legal_assessments"
                           mode="military_assessment" />

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

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

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



Jeni Tennison

 XSL-List info and archive:

Current Thread