[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xsl-list
Subject:    Re: [xsl] A use-case for xsl:merge?
From:       "Martin Honnen martin.honnen () gmx ! de" <xsl-list-service () lists ! mulberrytech ! com>
Date:       2019-02-16 9:55:17
Message-ID: 20190216045442.92926 () lists ! mulberrytech ! com
[Download RAW message or body]

Am 15.02.2019 um 23:53 schrieb John Dziurlaj john@hiltonroscoe.com:
>
> This is very helpful! I've tested it and it seems to work well, with the
> exception of CDATA. The output does not include the CDATA for <text>, which
> should be <text>This is some text</text>. I put this above
> <xsl:apply-templates select="." mode="merge-attributes"> and it seems to
> work:
> <xsl:value-of select="text()" />


I think I would prefer to delegate that to a added template with a 
different condition:

     <xsl:template match="*[not(*)]" mode="merge-children">
         <xsl:param name="prototype"/>
         <xsl:copy-of
              select="if (node()) then node() else $prototype/node()"/>
     </xsl:template>


> I guess I was fooled by the name of xsl:merge, it seems to be for merging
> sequences rather than content within sequences.

It can merge "content" but the main obstacle with your task to be seemed 
to be the lack of order of the possible child elements, if you group 
elements on node-name() as I have done then you don't need them ordered, 
for xsl:merge to work you would need to have them ordered or would need 
to first order them, see 
https://www.w3.org/TR/xslt-30/#merge-terminology wich defines


A*merge input sequence*is an arbitrarysequence 
<https://www.w3.org/TR/xpath-datamodel-30/#dt-sequence>^DM30 of items 
which is already sorted according to themerge key specification 
<https://www.w3.org/TR/xslt-30/#dt-merge-key-specification>for the 
correspondingmerge source definition 
<https://www.w3.org/TR/xslt-30/#dt-merge-source-definition>.

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/651070
or by email: xsl-list-unsub@lists.mulberrytech.com
--~--
[Attachment #3 (text/html)]

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Am 15.02.2019 um 23:53 schrieb John
      Dziurlaj <a class="moz-txt-link-abbreviated" \
href="mailto:john@hiltonroscoe.com">john@hiltonroscoe.com</a>:<br>  </div>
    <blockquote type="cite"
      cite="mid:20190215175312.95374@lists.mulberrytech.com">
      <pre class="moz-quote-pre" wrap="">

This is very helpful! I've tested it and it seems to work well, with the
exception of CDATA. The output does not include the CDATA for &lt;text&gt;, which
should be &lt;text&gt;This is some text&lt;/text&gt;. I put this above
&lt;xsl:apply-templates select="." mode="merge-attributes"&gt; and it seems to
work:
&lt;xsl:value-of select="text()" /&gt;
</pre>
    </blockquote>
    <p><br>
    </p>
    <p>I think I would prefer to delegate that to a added template with
      a different condition:</p>
    <p>    &lt;xsl:template match="*[not(*)]" mode="merge-children"&gt;<br>
              &lt;xsl:param name="prototype"/&gt;<br>
              &lt;xsl:copy-of <br>
                   select="if (node()) then node() else
      $prototype/node()"/&gt;<br>
          &lt;/xsl:template&gt;</p>
    <p><br>
    </p>
    <blockquote type="cite"
      cite="mid:20190215175312.95374@lists.mulberrytech.com">
      <pre class="moz-quote-pre" wrap="">
I guess I was fooled by the name of xsl:merge, it seems to be for merging
sequences rather than content within sequences. </pre>
    </blockquote>
    <p>It can merge "content" but the main obstacle with your task to be
      seemed to be the lack of order of the possible child elements, if
      you group elements on node-name() as I have done then you don't
      need them ordered, for xsl:merge to work you would need to have
      them ordered or would need to first order them, see
      <a class="moz-txt-link-freetext" \
href="https://www.w3.org/TR/xslt-30/#merge-terminology">https://www.w3.org/TR/xslt-30/#merge-terminology</a> \
wich defines</p>  <p><br>
    </p>
    <p><span style="color: rgb(0, 0, 0); font-family: sans-serif;
        font-size: medium; font-style: normal; font-variant-ligatures:
        normal; font-variant-caps: normal; font-weight: 400;
        letter-spacing: normal; orphans: 2; text-align: start;
        text-indent: 0px; text-transform: none; white-space: normal;
        widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
        background-color: rgb(255, 255, 255); text-decoration-style:
        initial; text-decoration-color: initial; display: inline
        !important; float: none;">A<span> </span></span><b style="color:
        rgb(0, 0, 0); font-family: sans-serif; font-size: medium;
        font-style: normal; font-variant-ligatures: normal;
        font-variant-caps: normal; letter-spacing: normal; orphans: 2;
        text-align: start; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial;">merge input sequence</b><span style="color: rgb(0, 0,
        0); font-family: sans-serif; font-size: medium; font-style:
        normal; font-variant-ligatures: normal; font-variant-caps:
        normal; font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: start; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial; display: inline !important; float: none;"><span> </span>is
        an arbitrary<span> </span></span><a
        href="https://www.w3.org/TR/xpath-datamodel-30/#dt-sequence"
        style="color: rgb(3, 69, 117); text-decoration: none;
        border-bottom: 1px solid rgb(187, 187, 187); padding: 0px 1px;
        margin: 0px -1px; font-family: sans-serif; font-size: medium;
        font-style: normal; font-variant-ligatures: normal;
        font-variant-caps: normal; font-weight: 400; letter-spacing:
        normal; orphans: 2; text-align: start; text-indent: 0px;
        text-transform: none; white-space: normal; widows: 2;
        word-spacing: 0px; -webkit-text-stroke-width: 0px;
        background-color: rgb(255, 255, 255);">sequence</a><sup
        style="vertical-align: super; font-size: 12.8px; color: rgb(0,
        0, 0); font-family: sans-serif; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: start; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial;"><small style="font-style: italic; color: rgb(143, 143,
          143);">DM30</small></sup><span style="color: rgb(0, 0, 0);
        font-family: sans-serif; font-size: medium; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: start; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial; display: inline !important; float: none;"><span> </span>of
        items which is already sorted according to the<span> </span></span><a
        title="merge key specification" class="termref"
        href="https://www.w3.org/TR/xslt-30/#dt-merge-key-specification"
        style="color: rgb(3, 69, 117); text-decoration: none;
        border-bottom: 1px solid rgb(187, 187, 187); padding: 0px 1px;
        margin: 0px -1px; font-family: sans-serif; font-size: medium;
        font-style: normal; font-variant-ligatures: normal;
        font-variant-caps: normal; font-weight: 400; letter-spacing:
        normal; orphans: 2; text-align: start; text-indent: 0px;
        text-transform: none; white-space: normal; widows: 2;
        word-spacing: 0px; -webkit-text-stroke-width: 0px;
        background-color: rgb(255, 255, 255);">merge key specification</a><span
        style="color: rgb(0, 0, 0); font-family: sans-serif; font-size:
        medium; font-style: normal; font-variant-ligatures: normal;
        font-variant-caps: normal; font-weight: 400; letter-spacing:
        normal; orphans: 2; text-align: start; text-indent: 0px;
        text-transform: none; white-space: normal; widows: 2;
        word-spacing: 0px; -webkit-text-stroke-width: 0px;
        background-color: rgb(255, 255, 255); text-decoration-style:
        initial; text-decoration-color: initial; display: inline
        !important; float: none;"><span> </span>for the corresponding<span> \
</span></span><a  title="merge source definition" class="termref"
        href="https://www.w3.org/TR/xslt-30/#dt-merge-source-definition"
        style="color: rgb(3, 69, 117); text-decoration: none;
        border-bottom: 1px solid rgb(187, 187, 187); padding: 0px 1px;
        margin: 0px -1px; font-family: sans-serif; font-size: medium;
        font-style: normal; font-variant-ligatures: normal;
        font-variant-caps: normal; font-weight: 400; letter-spacing:
        normal; orphans: 2; text-align: start; text-indent: 0px;
        text-transform: none; white-space: normal; widows: 2;
        word-spacing: 0px; -webkit-text-stroke-width: 0px;
        background-color: rgb(255, 255, 255);">merge source definition</a><span
        style="color: rgb(0, 0, 0); font-family: sans-serif; font-size:
        medium; font-style: normal; font-variant-ligatures: normal;
        font-variant-caps: normal; font-weight: 400; letter-spacing:
        normal; orphans: 2; text-align: start; text-indent: 0px;
        text-transform: none; white-space: normal; widows: 2;
        word-spacing: 0px; -webkit-text-stroke-width: 0px;
        background-color: rgb(255, 255, 255); text-decoration-style:
        initial; text-decoration-color: initial; display: inline
        !important; float: none;">.</span></p>
    <p><span style="color: rgb(0, 0, 0); font-family: sans-serif;
        font-size: medium; font-style: normal; font-variant-ligatures:
        normal; font-variant-caps: normal; font-weight: 400;
        letter-spacing: normal; orphans: 2; text-align: start;
        text-indent: 0px; text-transform: none; white-space: normal;
        widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
        background-color: rgb(255, 255, 255); text-decoration-style:
        initial; text-decoration-color: initial; display: inline
        !important; float: none;"><br>
      </span></p>
    <p><span style="color: rgb(0, 0, 0); font-family: sans-serif;
        font-size: medium; font-style: normal; font-variant-ligatures:
        normal; font-variant-caps: normal; font-weight: 400;
        letter-spacing: normal; orphans: 2; text-align: start;
        text-indent: 0px; text-transform: none; white-space: normal;
        widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
        background-color: rgb(255, 255, 255); text-decoration-style:
        initial; text-decoration-color: initial; display: inline
        !important; float: none;"><br>
      </span></p>
  </body>
</html>
<div><!-- begin bl.html.trailer -->
<div style="border-top:1px solid black; background-color: #dddddd;
color: #888888; font-size: smaller; padding: 5px; text-align: center;
font-family: arial,verdana,arial,sans-serif; margin-top:1em; clear:
both; margin: auto">
<a href="http://www.mulberrytech.com/xsl/xsl-list">
XSL-List info and archive</a>
<div style="text-align:center;">
<a style="color: blue;"
  href="http://lists.mulberrytech.com/unsub/xsl-list/651070"
> EasyUnsubscribe</a>
(<a style="color: blue;"
href="mailto:xsl-list-unsub@lists.mulberrytech.com?subject=remove"
> by email</a>)
</div>
</div>
<!-- end bl.html.trailer --></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic