xsl-list
[Top] [All Lists]

[xsl] A use-case for xsl:merge?

2019-02-15 13:08:42
Hello,



This is my first post! I’ve been working in XML for about 12 years, but
haven’t gotten into XSLT processing seriously until recently. I am tasked
to write an XSLT3 script to merge some XML. For purposes of my contrived
example, each draw element can reference a prototype (via the @usehref
element, representing a FQ XPath), which provides default values that can
be overridden by its referrer:



DRAW USING A PROTOTYPE (referrer):



<draw name="Text1" usehref="/proto/draw[name = *'TextStyle1'*]">

      <ui>

           <textEdit/>

      </ui>

      <value>

           <text>This is some text</text>

      </value>

      <border/>

      <font weight="bold"/>

</draw>



THE PROTOTYPE ITSELF:



<draw name="*TextStyle1*" w="29.2864mm" h="5.2331mm">

      <ui>

           <textEdit/>

      </ui>

      <border>

           <edge presence="hidden"/>

      </border>

      <font size="12pt" typeface="Myriad Pro"/>

      <margin topInset="0.5mm" bottomInset="0.5mm" leftInset="0.5mm"
rightInset="0.5mm"/>

</draw>



The expected result is a combination of all the elements under draw (order
of occurrence at any level does not matter). If an element or attribute is
defined by both the prototype and its referrer, the referring particle
should take precedence.



EXPECTED COMBINED RESULT:



<draw name="Text1" vAlign="top" h="5.2331mm" w="29.2864mm">

      <ui>

           <textEdit/>

      </ui>

      <value>

           <text>This is some text</text>

      </value>

      <border>

           <edge presence="hidden"/>

      </border>

      <font weight="bold" typeface="Myriad Pro" size="12pt"/>

      <margin bottomInset="0.5mm" leftInset="0.5mm" rightInset="0.5mm"
topInset="0.5mm"/>

</draw>



I tried to use the xsl:merge function in XSLT3 but I find the syntax a
little confusing. I’m using SAXON-PE 9.8.



John Dziurłaj



Elections Consultant

Hilton Roscoe LLC
Cell 330-714-8935 Work/Fax 234-706-6434



PGP Fingerprint: 8466 BB28 6A92 EE06 F71D 1519 FB42 2861 6DC0 E92C
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>