[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
Hi Chris, The idea was from Rick Jelliffe, although I donbt have the exact citation now. Here is a small example: A content model expressed in a RelaxNG-like syntax: <contexts> <context>contrib-group</context> </contexts> <model> <optional> <element name="on-behalf-of"/> </optional> <oneOrMore> <element name="contrib"/> </oneOrMore> <zeroOrMore> <choice> <element name="aff"/> <element name="aff-alternatives"/> <element name="bio"/> <element name="etal"/> </choice> </zeroOrMore> </model> This content model is transformed by XSLT into Schematron. This implementation ignores namespaces because it wasnbt a requirement at the time, but it is certainly possible to extend this implementation to support namespaces. <sch:rule context="contrib-group"> <sch:extends rule="JATS-0045-002a"/> </sch:rule> <sch:rule abstract="true" id="JATS-0045-002a"> <sch:let name="sequence" value="string-join(for $n in node() return if ($n instance of element()) then local-name($n) else if ($n instance of text() and normalize-space($n)) then '#PCDATA' else (), ',')"/> <sch:let name="allowed" value="('on-behalf-of','contrib','aff','aff-alternatives',' bio','etal')"/> <sch:let name="model-regex" value="'^(?:on-behalf-of)?,?(?:contrib,?)+,?(?:(?:aff|aff-a lternatives|bio|etal),?)*$'"/> <sch:let name="model-text" value="'(on-behalf-of)?, (contrib)+, ((aff | aff-alternatives | bio | etal))*'"/> <sch:assert test="matches($sequence, $model-regex)" id="JATS-0045-002" role="error">contrib-group <sch:value-of select="for $i in tokenize($sequence, ',') return if (not($i = $allowed)) then concat('Unexpected ', $i, '. ') else ()"/>Content of element <sch:name/> (<sch:value-of select="replace($sequence, ',', ', ')"/>) does not match model (<sch:value-of select="$model-text"/>)</sch:assert> </sch:rule> Here is an example of an error message: contrib-group Unexpected bio. Content of element contrib-group (bio, contrib, contrib, contrib, contrib, contrib, contrib, contrib, contrib, aff, aff, aff, aff, aff, aff, aff, aff, bio, bio, bio, bio, bio, bio, bio, bio) does not match model ((on-behalf-of)?, (contrib)+, ((aff | aff-alternatives | bio | etal))*) Cheers, Vincent _____________________________________________ Vincent M. Lizzi Head of Information Standards | Taylor & Francis Group vincent.lizzi@xxxxxxxxxxxxxxxxxxxx<mailto:vincent.lizzi@xxxxxxxxxxxxxxxxxxxx> From: Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Sent: Wednesday, February 22, 2023 3:38 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: inserting a child element while honoring the parent element's content model Hi Vincent, Wendell, I am interested in understanding how regular expressions are used to check/enforce content models. Could you help me understand this, perhaps with a simple example? * Chris Information Classification: General
|
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
|