Re: [xsl] clever ways to dynamically copy/create element structure as needed?

Subject: Re: [xsl] clever ways to dynamically copy/create element structure as needed?
From: "Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 1 Oct 2022 17:02:11 -0000
I forgot to mention one fun aspect. Sometimes the content models are
order-specific:

topic = element topic { title, titlealts?, (shortdesc | abstract)?, prolog?,
body?, related-links?, topic* }
prolog = element prolog { author*, source?, publisher?, copyright*,
critdates?, permissions?, (metadata | change-historylist)*, resourceid*, (data
| sort-as | data-about | foreign | mathml | svg-container | unknown)* }
metadata = element metadata { audience*, category*, keywords*, prodinfo*,
othermeta*, (data | sort-as | data-about | foreign | mathml | svg-container |
unknown)* }

so when new levels are created, they must be ordered correctly within whatever
siblings might already exist.


  *   Chris


From: Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Saturday, October 1, 2022 12:28 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] clever ways to dynamically copy/create element structure as
needed?

Hi everyone,

I want to use XSLT to add a piece of <data> metadata to a DITA topic. The DITA
content model lets me place it at "topic/prolog/metadata/data":

<topic id="topic">
  <title>My Topic</title>
  <prolog>
    <metadata>
      <data name="prefix">my-prefix</data>
    </metadata>
  </prolog>
  <body/>
</topic>

Some, none, or all of the required "prolog/metadata" element structure might
already exist:

<topic id="topic">
  <title>My Topic</title>
  <body/>
</topic>

<topic id="topic">
  <title>My Topic</title>
  <prolog>
    <author type="creator">chrispy</author>
    <metadata>
      <keywords>
        <indexterm>some term</indexterm>
      </keywords>
    </metadata>
  </prolog>
  <body/>
</topic>

My current XSLT code to do this is embarrassing.

Does anyone have a favorite way of adding an element at a particular hierarchy
path, copying existing levels and creating missing levels as needed?

(This is just an example. I have other scenarios that require deeper element
structures.)

Thanks!

-----
Chris Papademetrious
Tech Writer, Implementation Group
(610) 628-9718 home office
(570) 460-6078 cell

XSL-List info and
archive<https://urldefense.com/v3/__http:/www.mulberrytech.com/xsl/xsl-list__
;!!A4F2R9G_pg!a7r1m9ZqiV4eF0dRar7ijsLmZPDxguhK0RPYb5y02NTd6ZMhMJ-6OOgmwoGKssR
TCKpUEvPFIXTaNtIVe9rEW4v_YxwwyffaEgFRs9luLZH7nUeag425$>
EasyUnsubscribe<https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsu
b/xsl-list/3380743__;!!A4F2R9G_pg!a7r1m9ZqiV4eF0dRar7ijsLmZPDxguhK0RPYb5y02NT
d6ZMhMJ-6OOgmwoGKssRTCKpUEvPFIXTaNtIVe9rEW4v_YxwwyffaEgFRs9luLZH7nfTEHOTC$>
(by email<>)

Current Thread