xsl-list
[Top] [All Lists]

Re: [xsl] tokenize

2016-10-12 04:11:37
I can't see why you would expect anything different from what you are getting. 
When you do

<xsl:for-each select="tokenize(.,', ')">
  <xsl:if test=".!=''">
   <au><xsl:copy-of select="."/></au>
  </xsl:if>
 </xsl:for-each>

you are clearly outputting one <au> element for each token in the input, so I 
can't see why you would expect multiple tokens to be concatenated in a single 
<au> element.

I think that what you actually need to do here is positional grouping. If we 
simplified the input so it read

<p>
  <r>Amanda</r>
  <r>Ganem</r>
  <r>, M.D.</r>
  <r><sup>1</sup</r>
  <r>, </r>
  <r>Elias P. Bonaros</r>
  etc...
</p>

Then your logic would be

<xsl:template match="p">
  <xsl:for-each-group select="r" group-ending-with="r[. = ', ']">
    <au>
      <xsl:value-of select="current-group()/text()"/>
    </au>
 </xsl:for-each-group>
</xsl:template>

Perhaps you can work out how to adapt this to your more complex input. (It 
might even be worth writing your stylesheet in two phases: first get rid of the 
needless complexity in the input data, then do the "business logic" on the 
simplified XML).

Michael Kay
Saxonica

On 12 Oct 2016, at 09:55, Joga Singh Rawat jrawat(_at_)aptaracorp(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Hi Experts,

I am not getting the Expected Output by following inputs. Any idea? Thanks
in advance.

Input
<w:p>
 <w:pPr><w:pStyle w:val="Authors0"/></w:pPr>
 <w:r><w:t>Amanda
</w:t></w:r><w:r><w:t>Ganem</w:t></w:r><w:r><w:t>,M.D.</w:t></w:r>
 <w:r><w:rPr><w:vertAlign
w:val="superscript"/></w:rPr><w:t>1,¶,*</w:t></w:r>
 <w:r><w:t>, </w:t></w:r>
 <w:r><w:t>Elias P. Bonaros,M.D.</w:t></w:r>
 <w:r><w:rPr><w:vertAlign w:val="superscript"/></w:rPr><w:t>2</w:t></w:r>
 <w:r><w:t>, Bibiana D</w:t></w:r>
 <w:r><w:t>. Stephen</w:t></w:r>
 <w:r><w:rPr><w:vertAlign w:val="superscript"/></w:rPr><w:t>3</w:t></w:r>
 <w:r><w:t>, </w:t></w:r>
 <w:r><w:t>J.H. Calderon Jr</w:t></w:r>
 <w:r><w:rPr><w:vertAlign w:val="superscript"/></w:rPr><w:t>2</w:t></w:r>
 <w:r><w:t>, J.H. Calderon</w:t></w:r>
 <w:r><w:rPr><w:vertAlign w:val="superscript"/></w:rPr><w:t>5,6</w:t></w:r>
 <w:r><w:t xml:space="preserve">, </w:t></w:r>
 <w:r><w:t>W. WYAT Hoback</w:t></w:r>
 <w:r><w:rPr><w:vertAlign w:val="superscript"/></w:rPr><w:t>4,6</w:t></w:r>
</w:p>

Xslt
<xsl:template match="w:p">
  <xsl:if test="w:pPr/w:pStyle/@w:val='Authors0'">
   <aug>
    <xsl:apply-templates select="*" mode="make-tokens"/>
  </aug>
</xsl:if>
</xsl:template>
<xsl:template match="*" mode="make-tokens">
 <xsl:for-each select="tokenize(.,', ')">
  <xsl:if test=".!=''">
   <au><xsl:copy-of select="."/></au>
  </xsl:if>
 </xsl:for-each>
</xsl:template>
<xsl:template match="w:r[w:rPr/w:vertAlign/@w:val='superscript']"
mode="make-tokens">
 </xsl:variable>
 <sup><xsl:value-of select="."/></sup>
</xsl:template>

Current output
  <aug>
     <au>Amanda </au>
     <au>Ganem</au>
     <au>,M.D.</au>
     <sup>1,&amp;x00B6;,*</sup>
     <au>Elias P. Bonaros,M.D.</au>
     <sup>2</sup>
     <au>Bibiana D</au>
     <au>. Stephen</au>
     <sup>3</sup>
     <au>J.H. Calderon Jr</au>
     <sup>2</sup>
     <au>J.H. Calderon</au>
     <sup>5,6</sup>
     <au>W. WYAT Hoback</au>
     <sup>4,6</sup>
  </aug>

Expected output
  <aug>
     <au>Amanda Ganem,M.D. <sup>1,&amp;x00B6;,*</sup></au>
     <au>Elias P. Bonaros,M.D.<sup>2</sup></au>
     <au>Bibiana D. Stephen<sup>3</sup></au>
     <au>J.H. Calderon Jr<sup>2</sup></au>
     <au>J.H. Calderon<sup>5,6</sup></au>
     <au>W. WYAT Hoback<sup>4,6</sup></au>
  </aug>

--~----------------------------------------------------------------
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>
  • [xsl] tokenize, Joga Singh Rawat jrawat(_at_)aptaracorp(_dot_)com
    • Re: [xsl] tokenize, Martin Honnen martin(_dot_)honnen(_at_)gmx(_dot_)de
    • Re: [xsl] tokenize, Michael Kay mike(_at_)saxonica(_dot_)com <=