[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: inserting a child element while honoring the paren
Hey Chris (writing from a different address here), Exactly - I think we already touched on this thread how the union operator (a|b|c) has the effect of sorting in document order? In passing I am noting the difference between (a|b|c)[1]/(.|preceding-sibling::node()) and without that [1] positional predicate. Going to be quite a bit different. With respect to *testing* against (not processing in view of) content models - I hesitate to mention it but there is the approach of writing out the sequence of element names as a string and then testing that against a regex mapped out from the content model. One of several problems with this approach is that the error messages it produces are pretty useless.Limiting the content model in certain ways can make this easier e.g. forbidding repeated sequence groups (even worse than 'or' groups). Cheers, Wendell On Tue, Feb 21, 2023 at 12:53 PM Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > Hi Wendell, > > > > Thatbs 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), > > > > Ibve 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: 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 < > xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> > *Sent:* Monday, February 20, 2023 3:29 PM > *To:* xsl-list@xxxxxxxxxxxxxxxxxxxxxx > *Subject:* Re: inserting a child element while honoring the parent > element's content model > > > > Hi Eliot, > > > > I hadnbt known about these operators, thank you! > > > > I couldnbt see a clean way to use b<<b 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__;!!A4F2 R9G_pg!Z3nf-HGm4cQQ0xPYAPTIW7s2XVGPGxeUm8UkvupvKaxYpDgxu9bfeGyVc4wB7uAY2RvbN2 PpxzO8q8-B3hHzltXwWc3ulHu6OekNmOilvZ_7MYLVdnhD$> > > EasyUnsubscribe > <https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsub/xsl-list/3380 743__;!!A4F2R9G_pg!Z3nf-HGm4cQQ0xPYAPTIW7s2XVGPGxeUm8UkvupvKaxYpDgxu9bfeGyVc4 wB7uAY2RvbN2PpxzO8q8-B3hHzltXwWc3ulHu6OekNmOilvZ_7MYIZ-WDh$> > (by email) > XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> > EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/174322> (by > email <>) > -- ...Wendell Piez... ...wendell -at- nist -dot- gov... ...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org... ...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|