Re: Apply Comment Position

"Michael Müller-Hillebrand [email protected]" <[email protected]> Sat, 27 Feb 2021 19:10:08 -0000
Newsgroups gmane.text.xml.xsl.general.mulberrytech
Message-ID <[email protected]>
Hi,

Since I dig grouping Martin’s solution is clever and thanks for reminding me of tail()!

Depending on the underlying logic, you might rather loop over the ext-link:

<xsl:template match="article-meta">
  <xsl:copy>
    <xsl:for-each select="ext-link">
      <cp id="{@id}">
        <email>
          <xsl:value-of select="."/>
          <!-- pull in first preceding comment -->
          <xsl:copy-of select="preceding-sibling::node()[self::comment()][1]"/>
        </email>
      </cp>
    </xsl:for-each>
  </xsl:copy>
</xsl:template>

Happy coding,

- Michael


> Am 26.02.2021 um 08:25 schrieb Martin Honnen [email protected] <[email protected]>:
> 
> 
> On 26.02.2021 07:22, Martin Honnen [email protected] <mailto:[email protected]> wrote:
>> 
>> 
>> On 26.02.2021 06:13, Byomokesh Sahoo [email protected] wrote:
>>> Hi,
>>> 
>>> Please look at the below xml, xslt and required output. I tried position function to get the comment inside <mail> in respective <ext-link>. I am facing a problem where  ( <!--xmltex \gdef\EmailAuthIdDefnII{\MailAuthIdII}-->) refers to two <ext-link>. Could you please anyone help on this.
>> 
>> 
>> Which version of XSLT can you use? What defines a relation between a comment "xmltext" and an "ext-link" element? Can't that just be solved by
>> 
>>   <xsl:template match="article-meta">
>> 
>>     <xsl:copy>
>> 
>>       <xsl:for-each select="comment()[starts-with(., 'xmltext')] | ext-link" group-starting-with="comment()">
>> 
>>          <xsl:for-each select="tail(current-group())">
>> 
>>             <cp id="{@id}">
>> 
>>               <email>
>> 
>>                  <xsl:copy-of select="node(), current-group()[1]"/>
>> 
>>             </email>
>> 
>>          </cp>
>> 
>>      </xsl:for-each-group>
>> 
>>   </xsl:copy>
>> 
>> </xsl:template>
>> 
> 
> So that should have been
> 
> 
>    <xsl:template match="article-meta">
>       <xsl:copy>
>         <xsl:for-each-group select="comment()[starts-with(., 'xmltex')] | ext-link" group-starting-with="comment()">
>            <xsl:for-each select="tail(current-group())">
>               <cp id="{@id}">
>                 <email>
>                    <xsl:copy-of select="node(), current-group()[1]"/>
>                 </email>
>               </cp>
>             </xsl:for-each>
>        </xsl:for-each-group>
>     </xsl:copy>
>   </xsl:template>
> 
> 
> really, sorry, it seems without an editor I am not able to type well-formed and intended XSLT
> 
> 
> 
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/3329386
or by email: [email protected]
--~--