Re: [xsl] Creating new, distinct groups of ranges from an aggregation of individual ranges

Subject: Re: [xsl] Creating new, distinct groups of ranges from an aggregation of individual ranges
From: "Heiko Niemann kontakt@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 19 Nov 2014 01:20:10 -0000
Hi Gerrit,

since my first name is not very international I listen to a whole range of
names: from Heeeko to Hayoko. :)

Talking about ranges. I had the same question about 219, Michael clarified
and since your code covers it already I would suggest Michael to follow
your approach. They are similar anyhow.

I noticed two things though:

1) parsing the ranges does not cover missing leading zeros (if you e.g.
add 8880889 to a aircraft-range it won't show in the result, 08880889
will); first I also looked at using analyze-string but dropped it so I use
following code now (adjusted to the elements you use):


<xsl:for-each select="tokenize(., '\s+')">
  <xsl:if test=". castable as xs:integer">
    <xsl:variable as="xs:string" name="rng">
      <xsl:choose>
        <xsl:when test="string-length(.) le 4">
          <xsl:variable name="d4" select="format-number(number(.), '0000')"/>
          <xsl:value-of select="concat($d4,$d4)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="format-number(number(.), '00000000')"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <range start="{number(substring($rng,1,4))}"
end="{number(substring($rng,5,4))}"/>
  </xsl:if>
</xsl:for-each>

There probably are better ways.


2) If you add e.g. 0200 to a list the result will show:

<pass3>
    <range start="200" end="200"/>
    <range start="200" end="200"/>
    <range start="201" end="204"/>


and if you add 0201 instead the result is:

<pass3>
      <range start="201" end="200"/>
      <range start="201" end="201"/>
      <range start="202" end="204"/>


Cheers,
Heiko








>
>
> On 18.11.2014 23:53, Michael Friedman sumarimike@xxxxxxxxxxx wrote:
>> Greetings,
>>
>> Note: My first reply email was too long and was rejected by the system.
>> I hope this one is shorter. I removed the output, but it can be
>> reproduced using the below.
>>
>> Wow - great suggestions and assistance. Heiko, your solution is very
>> promising and is one I started testing. To answer your question, the gap
>> you identified should be missing. These new ranges only show what SHOULD
>> be output in the final XSLFO, so the gaps need to be omitted. Great
>> catch.
>
> If I process your input, the difference between filling these gaps and
> not filling these gaps will be this:
>
> with gaps filled:
> b&
> <range start="218" end="218"/>
> <range start="219" end="219"/>
> <range start="220" end="222"/>
> b&
>
> without gaps filled:
> b&
> <range start="218" end="218"/>
> <range start="220" end="222"/>
> b&
>
> I think the 219 stems from input token 02010222.
> So Ibd think that it should be included, shouldnbt it?
>
> Ibm sorry that I am stubbornly pursuing my own code, but here it is:
>
> aircrafts.xsl
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>    xmlns:xs="http://www.w3.org/2001/XMLSchema";
>    exclude-result-prefixes="xs"
>    version="2.0">
>
>    <xsl:import href="ranges.xsl"/>
>
>    <xsl:template match="group[aircraft-range]">
>      <xsl:variable name="parse" as="element(ranges)">
>        <ranges>
>          <xsl:apply-templates mode="parse"/>
>        </ranges>
>      </xsl:variable>
>      <xsl:apply-templates select="$parse"/>
>    </xsl:template>
>
>    <xsl:template match="aircraft-range" mode="parse">
>      <xsl:for-each select="tokenize(., '\s+')">
>        <xsl:analyze-string select="." regex="^(\d{{4}})(\d{{4}})?$">
>          <xsl:matching-substring>
>            <range start="{number(regex-group(1))}"
> end="{number((regex-group(2)[normalize-space()], regex-group(1))[1])}"/>
>          </xsl:matching-substring>
>          <xsl:non-matching-substring>
>            <xsl:message select="'Could not parse ', ."/>
>          </xsl:non-matching-substring>
>        </xsl:analyze-string>
>      </xsl:for-each>
>    </xsl:template>
>
> </xsl:stylesheet>
>
>
> ranges.xsl is almost the same as what I posted recently, with
> <xsl:template match="/ranges">
> changed to
> <xsl:template match="ranges">
>
> Pass3 output:
>
>      <pass3>
>        <range start="201" end="204"/>
>        <range start="205" end="205"/>
>        <range start="206" end="207"/>
>        <range start="208" end="210"/>
>        <range start="211" end="212"/>
>        <range start="213" end="213"/>
>        <range start="214" end="217"/>
>        <range start="218" end="218"/>
>        <range start="219" end="219"/>
>        <range start="220" end="222"/>
>        <range start="225" end="226"/>
>        <range start="228" end="228"/>
>        <range start="232" end="232"/>
>        <range start="235" end="235"/>
>        <range start="236" end="238"/>
>        <range start="239" end="239"/>
>        <range start="240" end="240"/>
>        <range start="251" end="252"/>
>        <range start="257" end="261"/>
>        <range start="262" end="263"/>
>        <range start="264" end="266"/>
>        <range start="267" end="269"/>
>        <range start="270" end="285"/>
>        <range start="286" end="287"/>
>        <range start="290" end="290"/>
>        <range start="292" end="292"/>
>        <range start="296" end="296"/>
>        <range start="401" end="405"/>
>        <range start="408" end="408"/>
>        <range start="411" end="411"/>
>        <range start="415" end="416"/>
>        <range start="451" end="452"/>
>        <range start="453" end="453"/>
>        <range start="454" end="455"/>
>        <range start="456" end="460"/>
>     </pass3>
>
> Gerrit

Current Thread