|
Subject: RE: [xsl] Expanding Ranges From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Thu, 19 Mar 2009 12:50:59 -0000 |
In XSLT 2.0 if you have the start and end of the range as integers $start
and $end, you can do
<xsl:value-of select="for $i in $start to $end return concat('fig', $i)"/>
In 1.0 you have to do a call on a named template that calls itself
recursively to process each number in the sequence.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Ganesh Babu N [mailto:nbabuganesh@xxxxxxxxx]
> Sent: 19 March 2009 12:31
> To: XSL
> Subject: [xsl] Expanding Ranges
>
> Dear All,
>
> My input is like below: the <cross-ref> tags are not
> continues it will come in between the content.
>
> <links>
> <p>some text <cross-ref><cr refid="MEPRfig2"> 2</cr>-<cr
> refid="MEPRfig4">4</cr></cross-ref> some text <cross-ref><cr
> refid="MEPRfig1">Figures 1</cr> and <cr
> refid="MEPRfig3">3</cr></cross-ref> some text</p>
>
> <p><cross-ref><cr refid="MEPRtbl1">1</cr>-<cr
> refid="MEPRtbl4">4</cr></cross-ref> some text <cross-ref><cr
> refid="MEPRtbl1">Tables 1</cr> and <cr
> refid="MEPRtbl2">2</cr></cross-ref> some text <cross-ref><cr
> refid="MEPRtbl1">Table1</cr></cross-ref> some text </p>
>
> <p>some text <cross-ref><cr refid="MEPRtbl1">1</cr>-<cr
> refid="MEPRtbl3">3</cr> and <cr refid="MEPRtbl4">4</cr></cross-ref>
> some text</p>
> </links>
>
> The required output will be like below:
>
> <links>
> <p>some text <cross-refs refid="fig2 fig3 fig4">
> 2-4</cross-refs> some text <cross-refs refid="fig1
> fig3">Figures 1 and 3</cross-refs> some text</p>
>
> <p><cross-refs refid="tbl1 tbl2 tbl3 tbl4">1-4</cross-refs>
> some text <cross-refs refid="tbl1 tbl2">Tables 1 and
> 2</cross-refs> some text <cross-ref
> refid="tbl1">Table1</cross-ref> some text </p>
>
> <p>some text <cross-refs refid="tbl1 tbl2 tbl3 tbl4">1-3 and
> 4</cross-refs> some text</p> </links>
>
> Here is the XSL which i have tried. I do not know how to
> expand the ranges. My style sheet is combining available
> attributes to single attribute. Please help me in getting
> ranges expanded.
>
> <xsl:template match="cross-ref">
> <xsl:choose>
> <xsl:when test="count(cr) = 1">
> <cross-ref refid="{substring-after(cr/@refid,'MEPR')}">
> <xsl:apply-templates/>
> </cross-ref>
> </xsl:when>
> <xsl:otherwise>
> <cross-refs>
> <xsl:attribute name="refid">
> <xsl:for-each select="cr">
> <xsl:value-of
> select="substring-after(@refid,'MEPR')"/>
> <xsl:if
> test="position() != last()">
> <xsl:text> </xsl:text>
> </xsl:if>
> </xsl:for-each>
> </xsl:attribute>
> <xsl:apply-templates/>
> </cross-refs>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> <xsl:template match="cr">
> <xsl:apply-templates/>
> </xsl:template>
>
> Regards,
> Ganesh
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Expanding Ranges, Ganesh Babu N | Thread | Re: [xsl] Expanding Ranges, Ganesh Babu N |
| [xsl] Expanding Ranges, Ganesh Babu N | Date | [xsl] debug stylesheet,str:tokenize, himanshu padmanabhi |
| Month |