Subject: Re: [xsl] inserting a child element while honoring the parent element's content model From: "Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 21 Feb 2023 17:52:46 -0000 |
Hi Wendell, That's mostly what I did in this template: <!-- add <j> to <topic>, honoring the following content model: topic = a?, b?, c?, j, x?, y?, z?, topic* --> <xsl:template match="topic[not(j)]" mode="add-j"> <xsl:variable name="stuff-before-j" select="(a|b|c)/(.|preceding-sibling::node())" as="node()*"/> <xsl:copy> <xsl:sequence select="@*|$stuff-before-j"/> <j/> <xsl:sequence select="node() except $stuff-before-j"/> </xsl:copy> </xsl:template> The part that was tricky for me at first was figuring out how to handle <a>, <b>, and <c> being present or absent in any combination. But this seems to work pretty well! Hi Eliot (again), I've been thinking that it would be nice to have some helper functions/templates to make DITA element insertion easier. For example, if I want to insert an <othermeta> element into a DITA topic: <topic> <title>...</title> <prolog> <author type="owner">myeong</author> <metadata> <othermeta content="foo" name="bar"/> </metadata> <resourceid appid="hile_repeatCopy"/> </prolog> <body>...</body> </topic> I would want to reuse whatever elements might already exist, or create missing elements as needed while honoring content models: topic = title, titlealts?, (shortdesc | abstract)?, prolog?, body?, related-links?, topic* } prolog = author*, source?, publisher?, copyright*, critdates?, permissions?, (metadata | change-historylist)*, resourceid*, (data | sort-as | data-about | foreign | mathml | svg-container | unknown)* metadata = audience*, category*, keywords*, prodinfo*, othermeta*, (data | sort-as | data-about | foreign | mathml | svg-container | unknown)* If I figure out a nice solution to this, I will let you know. * Chris From: Piez, Wendell A. (Fed) wendell.piez@xxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Sent: Tuesday, February 21, 2023 10:36 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] inserting a child element while honoring the parent element's content model Chris, How about (.|preceding-sibling::node), as in $fromhere/(.|preceding-sibling::node()) ? Also useful for counting, as in count(self::h1|preceding-sibling::h1). Cheers, Wendell From: Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx<mailto:christopher.papademetrious@syn opsys.com> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx rytech.com>> Sent: Monday, February 20, 2023 3:29 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Subject: Re: [xsl] inserting a child element while honoring the parent element's content model Hi Eliot, I hadn't known about these operators, thank you! I couldn't see a clean way to use "<<" for a preceding-sibling-or-self:: axis for this specific case, but I will definitely keep these operators in mind for future DiTA processing tasks. * Chris XSL-List info and archive<https://urldefense.com/v3/__http:/www.mulberrytech.com/xsl/xsl-list__ ;!!A4F2R9G_pg!Z3nf-HGm4cQQ0xPYAPTIW7s2XVGPGxeUm8UkvupvKaxYpDgxu9bfeGyVc4wB7uA Y2RvbN2PpxzO8q8-B3hHzltXwWc3ulHu6OekNmOilvZ_7MYLVdnhD$> EasyUnsubscribe<https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsu b/xsl-list/3380743__;!!A4F2R9G_pg!Z3nf-HGm4cQQ0xPYAPTIW7s2XVGPGxeUm8UkvupvKax YpDgxu9bfeGyVc4wB7uAY2RvbN2PpxzO8q8-B3hHzltXwWc3ulHu6OekNmOilvZ_7MYIZ-WDh$> (by email<>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] inserting a child element, Piez, Wendell A. (Fe | Thread | Re: [xsl] inserting a child element, Wendell Piez wapiez@ |
Re: [xsl] inserting a child element, Piez, Wendell A. (Fe | Date | Re: [xsl] inserting a child element, Wendell Piez wapiez@ |
Month |