xsl-list
[Top] [All Lists]

Re: [xsl] Apply Comment Position

2021-02-26 00:22:41

On 26.02.2021 06:13, Byomokesh Sahoo sahoo(_dot_)byomokesh(_at_)gmail(_dot_)com 
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>



INPUT --
<article>
<article-meta>
<!--xmltex \gdef\EmailAuthIdDefnI{\MailAuthIdI}-->
<ext-link ext-link-type="email" id="42em1">hadiao@nencn</ext-link>
<!--xmltex \gdef\EmailAuthIdDefnII{\MailAuthIdII}-->
<ext-link ext-link-type="email" id="42em2">uip(_at_)gmail(_dot_)com
<mailto:uip(_at_)gmail(_dot_)com></ext-link>
<!--xmltex \gdef\EmailAuthIdDefnII{\MailAuthIdII}-->
<ext-link ext-link-type="email" id="42em3">gyuliu@hkbu</ext-link>
<ext-link ext-link-type="email" id="em4">90727(_at_)qq(_dot_)com
<mailto:90727(_at_)qq(_dot_)com></ext-link>
<!--xmltex \gdef\EmailAuthIdDefnIV{\MailAuthIdIV}-->
<ext-link ext-link-type="email" id="em5">sdu(_at_)math(_dot_)hk
<mailto:sdu(_at_)math(_dot_)hk></ext-link>
</article-meta>
</article>
REQUIRED OUTPUT: --

<article>
   <article-meta>
      <cp id="42em1">
         <email>hadiao@nencn<!--xmltex
\gdef\EmailAuthIdDefnI{\MailAuthIdI}--></email>
      </cp>
      <cp id="42em2">
         <email>uip(_at_)gmail(_dot_)com 
<mailto:uip(_at_)gmail(_dot_)com><!--xmltex
\gdef\EmailAuthIdDefnII{\MailAuthIdII}--></email>
      </cp>
      <cp id="42em3">
         <email>gyuliu@hkbu<!--xmltex
\gdef\EmailAuthIdDefnII{\MailAuthIdII}--></email>
      </cp>
      <cp id="em4">
         <email>90727(_at_)qq(_dot_)com 
<mailto:90727(_at_)qq(_dot_)com><!--xmltex
\gdef\EmailAuthIdDefnIV{\MailAuthIdIII}--></email>
      </cp>
      <cp id="em5">
         <email>sdu(_at_)math(_dot_)hk <mailto:sdu(_at_)math(_dot_)hk><!--xmltex
\gdef\EmailAuthIdDefnIV{\MailAuthIdIV}--></email>
      </cp>
   </article-meta>
</article>

My XSLT: --

<xsl:template match="article">
<article>
<xsl:apply-templates/>
</article>
</xsl:template>

<xsl:template match="article-meta">
<xsl:element name="article-meta">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="comment()">
<xsl:copy/>
</xsl:template>

<xsl:template match="ext-link[position()=1]">
<xsl:if test="@ext-link-type='email'[position()=1]">
<xsl:element name="cp">
<xsl:attribute name="id">
<xsl:value-of select="@id"/>
</xsl:attribute>

<email>
<xsl:apply-templates/>
<xsl:apply-templates
select="ancestor-or-self::article-meta/comment()[matches(.,
'EmailAuthIdDefn')][position()=1]"/>
</email>
</xsl:element>
</xsl:if>
</xsl:template>
<xsl:template match="ext-link[position()=2]">
<xsl:if test="@ext-link-type='email'[position()=1]">
<xsl:element name="cp">
<xsl:attribute name="id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<email>
<xsl:apply-templates/>
<xsl:apply-templates
select="ancestor-or-self::article-meta/comment()[matches(.,
'EmailAuthIdDefn')][position()=2]"/>
</email>
</xsl:element>
</xsl:if>
</xsl:template>
<xsl:template match="ext-link[position()=3]">
<xsl:if test="@ext-link-type='email'[position()=1]">
<xsl:element name="cp">
<xsl:attribute name="id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<email>
<xsl:apply-templates/>
<xsl:apply-templates
select="ancestor-or-self::article-meta/comment()[matches(.,
'EmailAuthIdDefn')][position()=3]"/>
</email>
</xsl:element>
</xsl:if>
</xsl:template>
<xsl:template match="ext-link[position()=4]">
<xsl:if test="@ext-link-type='email'[position()=1]">
<xsl:element name="cp">
<xsl:attribute name="id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<email>
<xsl:apply-templates/>
<xsl:apply-templates
select="ancestor-or-self::article-meta/comment()[matches(.,
'EmailAuthIdDefn')][position()=4]"/>
</email>
</xsl:element>
</xsl:if>
</xsl:template>
<xsl:template match="ext-link[position()=5]">
<xsl:if test="@ext-link-type='email'[position()=1]">
<xsl:element name="cp">
<xsl:attribute name="id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<email>
<xsl:apply-templates/>
<xsl:apply-templates
select="ancestor-or-self::article-meta/comment()[matches(.,
'EmailAuthIdDefn')][position()=5]"/>
</email>
</xsl:element>
</xsl:if>
</xsl:template>

Thanks
Byomokesh
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/582271>
(by email <>)
--~----------------------------------------------------------------
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>