2

xslt を使用してテキスト ファイルを生成しています。xml 入力を渡すと、xslt は xml 入力をテキスト ファイルとして変換します。呼び出しごとにシーケンス番号を提供できますか。

そしてそれをいくつかの変数に格納します。

1)初めての実行で 1 つのテキスト ファイルが作成され、xslt ( <sequence>) 内に変数があると仮定すると、以下のように番号 1 として割り当てる必要があります。

<sequence>1</sequence>

2) 2 回目の実行では、もう 1 つのテキスト ファイルが作成されるため、シーケンス変数が増加します。

<sequence>2<sequence>

3) 3回目の実行でもう1つテキストファイルが作成されるので、シーケンスはこのようになります

<sequence>3</sequence>

これは通常、Oracle データベースでシーケンスを作成し、xslt 内でそのシーケンスを呼び出し、実行ごとにシーケンスが増加することで実行できます。

<sequence>CallOracleSequence</sequence>

Oracleシーケンスを使用せずに提案してください。これをxslt内で処理できますか。

4

3 に答える 3

0

通常、シーケンス番号は入力内の何かに関連するため、position()またはを使用できますxsl:number。ただし、詳細は入力の構造によって異なります。

于 2013-04-06T09:04:33.957 に答える
0

XSLT は、変換の実行間で状態を維持しません。

1 つのオプションは、シーケンス番号を含む外部構成ファイルを活用することです。エンティティ参照を使用すると、XSLT ドキュメントの XML 構成部分を作成して現在の値を読み取り、XSLT の実行時に番号をインクリメントして、.xml を使用して新しいシーケンス番号で構成ファイルを上書きできます<xsl:result-document>

以下は、実行中の XSLT と同じディレクトリに呼び出されるシーケンス ファイルがあることを前提としたXSLT 2.0スタイルシートの実例です。sequence.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--delare entities to reference the sequence file-->
<!DOCTYPE xsl:stylesheet [
<!ENTITY sequenceFile SYSTEM "sequence.xml">
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

    <xsl:output name="sequenceOutput" method="xml" indent="yes"/> 

  <!--this variable is used to store the expanded entity reference for 
      the current sequence.xml file
    When the XSLT is parsed it will "look" like this to the XML parser:
    <xsl:variable name="sequence><sequence>1</sequence></xsl:variable>
  -->
    <xsl:variable name="sequence">
        <!--
        this entity reference will expand to: 
            <sequence>x</sequence> 
        when the XSLT is parsed
        -->
        &sequenceFile;
    </xsl:variable>
   <!--
    Use the document() function with an empty value to read the XSLT 
    and then parse the sequence value produced by the entity reference
   -->
    <xsl:variable name="currentSequenceValue" 
      select="number(document('')/*/xsl:variable[@name='sequence']/sequence)"/>

    <xsl:template match="/">
        <!--do normal processing of the XML document-->
        <xsl:apply-templates />

        <!--
        This will overwrite the sequence file with the incremented value
        -->
        <xsl:result-document format="sequenceOutput" href="sequence.xml">
          <sequence><xsl:value-of select="$currentSequenceValue+1"/></sequence>
        </xsl:result-document>

    </xsl:template>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>
于 2013-04-06T18:46:28.107 に答える