xsl-list
[Top] [All Lists]

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

2014-11-18 17:38:18


On 18.11.2014 23:53, Michael Friedman sumarimike(_at_)hotmail(_dot_)com 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:
…
<range start="218" end="218"/>
<range start="219" end="219"/>
<range start="220" end="222"/>
…

without gaps filled:
…
<range start="218" end="218"/>
<range start="220" end="222"/>
…

I think the 219 stems from input token 02010222.
So I’d think that it should be included, shouldn’t it?

I’m 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
--~----------------------------------------------------------------
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>