Re: Apply Comment Position
| Newsgroups | gmane.text.xml.xsl.general.mulberrytech |
|---|---|
| Message-ID | <[email protected]> |
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> > > > 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">[email protected] > <mailto:[email protected]></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">[email protected] > <mailto:[email protected]></ext-link> > <!--xmltex \gdef\EmailAuthIdDefnIV{\MailAuthIdIV}--> > <ext-link ext-link-type="email" id="em5">[email protected] > <mailto:[email protected]></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>[email protected] <mailto:[email protected]><!--xmltex > \gdef\EmailAuthIdDefnII{\MailAuthIdII}--></email> > </cp> > <cp id="42em3"> > <email>gyuliu@hkbu<!--xmltex > \gdef\EmailAuthIdDefnII{\MailAuthIdII}--></email> > </cp> > <cp id="em4"> > <email>[email protected] <mailto:[email protected]><!--xmltex > \gdef\EmailAuthIdDefnIV{\MailAuthIdIII}--></email> > </cp> > <cp id="em5"> > <email>[email protected] <mailto:[email protected]><!--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/3329386 or by email: [email protected] --~--