Comment detail

変形Fizz-Buzz問題 (Nested Flatten)
if すら使わずに。
# XSLTプロセッサによっては曖昧なマッチでエラーになるかも..
 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
30
31
32
33
34
35
36
<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"
  >

  <xsl:output method="text" />

  <xsl:template match="/" >
    <xsl:for-each select="1 to 20">
      <xsl:value-of select="." />
      <xsl:text> : </xsl:text>
      <xsl:variable name="elm" as="element()">
        <xsl:element name="n">
          <xsl:value-of select="." />
        </xsl:element>
      </xsl:variable>
      <xsl:apply-templates select="$elm" />
      <xsl:text>&#xA;</xsl:text>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="n">
    <xsl:text>hoge</xsl:text>
  </xsl:template>
  <xsl:template match="n[(. mod 3)=0]">
    <xsl:text>Fizz</xsl:text>
  </xsl:template>
  <xsl:template match="n[(. mod 5)=0]">
    <xsl:text>Buzz</xsl:text>
  </xsl:template>
  <xsl:template match="n[(. mod 3)=0 and (. mod 5)=0]">
    <xsl:text>FizzBuzz</xsl:text>
  </xsl:template>

</xsl:stylesheet>

Index

Feed

Other

Link

Pathtraq

loading...