更新: 2012 年 9 月 18 日、午後遅く 101.(a) はここに余分であり、私が必要とするものの上の祖先::*[@belcode] です。それらは以下の XML サンプルにありますが、それらを取得しない方法を理解できませんでした。
不適切な XML 出力のサンプル:
<p style="I24">101.(a)(e)(1)(A) If the Attorney General determines that a licensee under this section has willfully violated any provision of this chapter or any regulation prescribed under this chapter, the Attorney General may—</p>
ベルコードを使用した for-each のみが正しく動作しない XSL:
<xsl:choose>
<xsl:when test="../@display-inline='yes-display-inline'">
<xsl:for-each select="ancestor-or-self::*[@belcode!='' and not(../@belcode/text or ../@belcode/header)]/enum">
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:for-each select="ancestor-or-self::*[@display-inline='yes-display-inline']/enum">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="../enum"/>
<xsl:text></xsl:text>
</xsl:otherwise>
</xsl:choose>
更新: 2012 年 9 月 18 日 提供されたコードをテストしましたが、外部条件が機能していませんでした... また、XSLT 2.0 を使用しているため、for-each は必要ありません。
QUITE が機能しない (先祖が多すぎる) 新しい XML 出力ですが、正しい p 要素でのみ取得しています:
<section number="101">
<title style="I72">SEC. 101. SECTION TITLE.</title>
<p style="I20">(a)cpk2 In General.—Section 923...</p>
<p style="I20">(e)</p>
<p style="I22">(1)</p>
<p style="I24">  “I 101. (a) (e) (1) (A)cpk1 If the ... may—</p>
<p style="I26">(i)cpk2 if the violation is of a minor nature—</p>
</section>
非常に近い XSLT コードであり、より多くの作業が必要なのは「だと思います」。belcode 属性を持つ最初の祖先からのみ子列挙型要素を取得する必要があり、テキスト要素の親の子である列挙型に戻ります。
value-of の * を、必要な最上位の祖先を返すものに置き換える必要があると考えています。私は XPath/XSLT にかなり慣れていないため、構文と戦っています。
<xsl:choose>
<xsl:when test="../@display-inline='yes-display-inline' and ancestor::*/@belcode[1]">
<xsl:value-of select="ancestor-or-self::*/enum"/>
<xsl:text>cpk1</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="../enum"/>
<xsl:text>cpk2</xsl:text>
</xsl:otherwise>
</xsl:choose>
可能なアドバイスをよろしくお願いします。
コードを持ち、display-inline="yes-display を持たない祖先に到達するまで、subclause-text ノードからツリーを上に移動するにはどうすればよいですか (要素テキストには名前を付けていないことを約束します)。 -inline」で、すべての子「enum」を包括的に取得しますか? 途中のすべての祖先要素にもヘッダーまたはテキストの子はありませんが、列挙型はあります。(はい、XML の例があります)。
バックグラウンド:
セクション/サブセクション/パラグラフ/サブパラグラフ/節 (それぞれに列挙型、ヘッダー、テキストの子を含めることもできます) を使用して XML入力をネストしました。これはフラット化されて、使用されたものとは異なるスタイルの「p」でいっぱいのセクションを出力します。 「enum」、「header」、「text」がすべて「p」に入れられるサブレベルになります。
私が問題を抱えているのは、以下のサンプルのように、1 つ以上のレベルの列挙しかない場合があることです。出力段落は、「ヘッダー」または「テキスト」のない最初のレベルのコード属性 (スタイルに変換されたもの) を取得することになっています。 「p」ラッパーが出力を取得するため、フラット化が適切に行われます。英語にすると、 (p style="P20")(e)(1)(A) が必要です。
ネストされた XML 入力:
<section code="P72">
<enum>101.</enum>
<header>SECTION TITLE.</header>
<subsection code="P20">
<enum>(e)</enum>
<paragraph display-inline="yes-display-inline">
<enum>(1)</enum>
<subparagraph display-inline="yes-display-inline">
<enum>(A)</enum>
<text>If the ... may—</text>
<clause belcode="I24">
<enum>(i)</enum>
<text>if the violation is of a minor nature—</text>
</clause>
</subparagraph>
</paragraph>
</subsection>
</section>
望ましい出力:
<section number="101">
<title style="I72">SEC. 101. SECTION TITLE.</title>
<p style="I20">(a) In General.—Section 923...</p>
<p style="I20">(e)(1)(A) If the ... may—</p>
<p style="I24">(i) if the violation is of a minor nature—</p>
</section>
私が得ている出力:
<section number="101">
<title style="I72">SEC. 101. SECTION TITLE.</title>
<p style="I20">(a) In General.—Section 923...</p>
<p style="I20">(e)</p>
<p style="I22">(1)</p>
<p style="I24">(A) If the ... may—</p>
<p style="I26">(i) if the violation is of a minor nature—</p>
</section>
機能しない XSL スニペット:
<xsl:template match="//subparagraph/text">
<p><xsl:attribute name="style"><xsl:value-of select="parent::subparagraph/@code"/></xsl:attribute>
<xsl:choose>
<xsl:when test="ancestor::*/enum and not(boolean(ancestor::*/header) or boolean(ancestor::*/text))"><xsl:value-of select="ancestor-or-self::*/enum"/><xsl:text> </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="../enum"/><xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
</p><xsl:text> </xsl:text>
</xsl:when>
</xsl:template>
これは単なる //subparagraph/text ピースであることに気付きましたが、出力列挙型を表示する必要がある部分であり、必要な場所に取得したら、他の場所での表示を停止する方法を知っています。