[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: how find out end position using 'for' loop

Subject: Re: how find out end position using 'for' loop
From: Olivier Jeulin <olivier.jeulin@xxxxxxxxx>
Date: Wed, 15 Jun 2011 00:14:26 +0200
Re:  how find out end position using 'for' loop
Le 14/06/2011 06:47, JS Rawat a C)crit :
Hi Everybody,
Have anyone any idea about the below problem. I want + sign between two RefArray (RefArray[11] + RefArray[12]) but not in the last (RefArray[12]+ RefArray[13]+ should be RefArray[12]+ RefArray[13]).

Input
<link class="bibcit" rid="FileName_bib11">11&#x2013;13</link>

XSLT

<xsl:template match="link">
  <xsl:choose>
   <xsl:when test="@class='bibcit'">
      <xsl:variable name="bibtext" select="."/>
      <xsl:choose>
       <xsl:when test="contains($bibtext, '&#x2013;') and substring-before($bibtext,'&#x2013;') castable as xs:integer">
         <xsl:variable name="start" select="xs:integer(substring-before($bibtext,'&#x2013;'))"/>
         <xsl:variable name="end" select="xs:integer(substring-after($bibtext,'&#x2013;'))"/>
         <a class="bibcit" href="references.htm#{substring-after(@rid,'_')}" onmouseout="startTimeout()">
          <xsl:attribute name="onmouseover">refpopup('REF',<xsl:value-of select="for $i in $start to $end return concat('RefArray[',$i,']+')"/>)</xsl:attribute><xsl:apply-templates/></a>
       </xsl:when>
      </xsl:choose>
    </xsl:when>
   </xsl:choose>
</xsl:template>

OUTPUT
<a class="bibcit" href="references.htm#bib11" onmouseout="startTimeout()" onmouseover="refpopup('REF',RefArray[11]+ RefArray[12]+ RefArray[13]+)">11C"b,b13</a>


Desired OUTPUT <a class="bibcit" href="references.htm#bib11" onmouseout="startTimeout()" onmouseover="refpopup('REF',RefArray[11]+ RefArray[12]+ RefArray[13])">11C"b,b13</a>

Hi
Another (better?) answer:
<xsl:value-of select="string-join(for $i in $start to $end return concat('RefArray[',$i,']'), '+')"/>


string-join() does exactly what you want : add a separator between strings.


You could also use <xsl:text> for your text values. Doing that allows you to (auto-)indent your text, it's a lot easier to read:
<a class="bibcit" href="references.htm#{substring-after(@rid,'_')}" onmouseout="startTimeout()">
<xsl:attribute name="onmouseover">
<xsl:text>refpopup('REF',</xsl:text>
<!--<xsl:value-of select="for $i in $start to $end return concat('RefArray[',$i,']+')"/>-->
<xsl:value-of select="string-join(for $i in $start to $end return concat('RefArray[',$i,']'), '+')"/>
<xsl:text>)</xsl:text>
</xsl:attribute>
<xsl:apply-templates/>
</a>


--
Regards,
Olivier Jeulin

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.