Comment detail

隣り合う二項の差 (Nested Flatten)
ふつーに。
与えるsequenceの要素が2個未満の場合は
エラーにしちゃってます。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:fn="http://www.w3.org/2005/xpath-functions"
  xmlns:my="uri:ja.doukaku.org:my-functions"
  exclude-result-prefixes="my"
  >

  <xsl:output method="text" />

  <xsl:template match="/" >
    <xsl:value-of select="my:diff((3,1,4,1,5,9,2,6,5))" />
  </xsl:template>

  <xsl:function name="my:diff" as="xs:integer*">
    <xsl:param name="seq" as="xs:integer*" />

    <xsl:if test="fn:count($seq)&lt;2">
      <xsl:message terminate="yes">
        sequence must have 2 or more elements
      </xsl:message>
    </xsl:if>

    <xsl:for-each select="2 to fn:count($seq)">
      <xsl:variable name="idx" as="xs:integer" select="." />
      <xsl:sequence select="$seq[$idx] - $seq[$idx - 1]" />
    </xsl:for-each>
  </xsl:function>
</xsl:stylesheet>

Index

Feed

Other

Link

Pathtraq

loading...