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

Re: number collapsing

Subject: Re: number collapsing
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Tue, 14 Dec 2004 09:47:46 -0500
xsl idiv
On Dec 14, 2004, at 9:41 AM, David Carlisle wrote:

Not sure if by "fail" you mean the <xsl:when test tests as false or you
get a type error reported. And also not sure if by "an integer" you
mean
a value of that type in the xpath type system or something that looks
like an intger, eg "123".

I'm not sure either :-)


Here's an example template:

  <xsl:template match="mods:extent[@unit='page']">
    <xsl:param name="prefix"/>
    <xsl:param name="suffix"/>
    <xsl:value-of select="$prefix"/>
    <span class="pages">
      <xsl:text> pp. </xsl:text>
      <xsl:value-of select="mods:start"/>
      <xsl:if test="mods:end">
        <xsl:text></xsl:text>
        <xsl:value-of
select="bib:number-condense(mods:start,mods:end)"/>
      </xsl:if>
    </span>
    <xsl:value-of select="$suffix"/>
  </xsl:template>

.... and the original function:

  <xsl:function name="bib:number-condense">
    <xsl:param name="begin"/>
    <xsl:param name="end"/>
    <xsl:choose>
      <xsl:when test="$begin castable as xs:integer">
        <xsl:variable name="begin" select="$begin" as="xs:integer"/>
        <xsl:choose>
          <xsl:when test="$begin gt 100 and $begin mod 100 and $begin
idiv 100 eq $end idiv 100">
            <xsl:value-of select="$end mod 100"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$end"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$end"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:function>

It has not failed yet (as in, Saxon never stops in its tracks with a
type error, and it formats the page ranges as I expect them to be
formatted), but it's not been widely tested.

Bruce

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-2013 All Rights Reserved.