Re: [xsl] multiple range expansion

Subject: Re: [xsl] multiple range expansion
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 23 Jun 2009 08:05:05 -0400
At 2009-06-23 11:22 +0530, Ganesh Babu N wrote:
I got the concept and converted successfully. Instead of for-each i
have used for to get spaces between ids.

But that didn't work for you ... what is wrong with <xsl:for-each>?


But one place i am unable to
remove. Please help to achieve this.

Input:

<cross-ref>[<cr refid="MEP_L_bib5">5</cr>-<cr
refid="MEP_L_bib7">7</cr>, <cr refid="MEP_L_bib21">21</cr>-<cr
refid="MEP_L_bib24">24</cr>]</cross-ref>

correct output:
<cross-refs refid="bib5 bib6 bib7 bib21 bib22 bib23 bib24">[5-7,
21-24]</cross-refs>

Output from modified XSL:
<cross-refs refid="bib5 bib6 bib7bib21 bib22 bib23 bib24">[5-7,
21-24]</cross-refs>

Modified XSL code:
<xsl:analyze-string select="." regex="(\d+)(\s*-\s*(\d+))?">
  <xsl:matching-substring>
     <xsl:value-of select="for $i in xs:integer(regex-group(1)) to
(if(regex-group(3)) then xs:integer(regex-group(3)) else
xs:integer(regex-group(1))) return concat('bib', $i)"/>

You didn't copy my concat() as I wrote it, which had the space added.


Just add <xsl:text> </xsl:text> after the <xsl:value-of> and then you are guaranteed to have a space after every token. The last is also included, but that should be irrelevant to the semantics of your attribute value.

For example, in XML and IDREFS attribute can have an arbitrary number of spaces before or after any of the contained IDREF values.

Please suggest. bib7 and bib21 has to be separated.

And they would be if you added a space after every token using <xsl:for-each> or add a space after every use of <xsl:value-of>.


As I evidenced above, a token list is typically allowed to have extra spaces in it. You might be worried about aesthetics, but is that a human looking at it or is it a syntactic constraint you've imposed on the input? Writing a stylesheet for this data I would still probably run normalize-space() on the value before tokenizing to ensure there were no extra spaces.

I hope this helps.

. . . . . . . . . . Ken

--
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread