-1

こんにちは私は以下のxmlコードを持っています。

    <toc-div>
                <toc-item num="1.">
                    <toc-title>Introduction</toc-title>
                    <toc-pg>2.001</toc-pg>
                </toc-item>
                <toc-item num="(a)">
                    <toc-title>Transitional arrangements</toc-title>
                    <toc-pg>2.003</toc-pg>
                </toc-item>
                <toc-item num="(b)">
                    <toc-title>Classifying by numbers</toc-title>
                    <toc-pg>2.006</toc-pg>
                </toc-item>
                <toc-item num="2.">
                    <toc-title>Incorporation</toc-title>
                    <toc-pg>2.009</toc-pg>
                </toc-item>
</toc-div>

ここで、tocアイテムに番号がある場合はxsltで1として出力し、それ以外の場合は2にします。方法を教えてください。条件を使用できることは知っていますが、ノードに数値が含まれている場合にそのステートメントを作成する方法を知りたいです。

ありがとう

4

1 に答える 1

0

このようなもの?

<xsl:template match="toc-item">
   <xsl:variable name="num" select="number(translate(@num, '.', ''))" />
   <xsl:variable name="chapter" select="1 + ($num != $num)" />

   ....
</xsl:template>

このXSLTで使用する場合:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="toc-item">
    <xsl:variable name="num" select="number(translate(@num, '.', ''))" />
    <!-- NaN != NaN evaluates to true(). -->
    <xsl:variable name="chapter" select="1 + ($num != $num)" />

    <xsl:value-of select="concat($chapter, '&#xA;')" />
  </xsl:template>
</xsl:stylesheet>

サンプル入力で実行すると、次のようになります。

1
2
2
1
于 2013-03-04T08:37:38.133 に答える