1

更新: 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&mdash;</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.&mdash;Section 923...</p>
<p style="I20">(e)</p>
<p style="I22">(1)</p>
<p style="I24">&ensp;&ensp;&ldquo;I 101. (a) (e) (1) (A)cpk1 If the ... may&mdash;</p>
<p style="I26">(i)cpk2 if the violation is of a minor nature&mdash;</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—&lt;/text>
<clause belcode="I24">
<enum>(i)</enum>
<text>if the violation is of a minor nature—&lt;/text>
</clause>
</subparagraph>
</paragraph>
</subsection>
</section>

望ましい出力:

<section number="101">
<title style="I72">SEC. 101. SECTION TITLE.</title>
<p style="I20">(a) In General.&mdash;Section 923...</p>
<p style="I20">(e)(1)(A) If the ... may&mdash;</p>
<p style="I24">(i) if the violation is of a minor nature&mdash;</p>
</section>

私が得ている出力:

<section number="101">
<title style="I72">SEC. 101. SECTION TITLE.</title>
<p style="I20">(a) In General.&mdash;Section 923...</p>
<p style="I20">(e)</p>
<p style="I22">(1)</p>
<p style="I24">(A) If the ... may&mdash;</p>
<p style="I26">(i) if the violation is of a minor nature&mdash;</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>&#10;</xsl:text>
</xsl:when>
</xsl:template>

これは単なる //subparagraph/text ピースであることに気付きましたが、出力列挙型を表示する必要がある部分であり、必要な場所に取得したら、他の場所での表示を停止する方法を知っています。

4

1 に答える 1

0

XSLT 1.0 で作業しているに違いないと思います。xsl:value-of要素に引数として複数のノードが指定されている場合、最初のノードの値を取得し、他のノードを無視します。1.0 を使用している場合は、置き換えてみてください。

<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:when test="ancestor::*/enum 
                and not(boolean(ancestor::*/header) 
                     or boolean(ancestor::*/text))">
  <xsl:for-each select="ancestor-or-self::*/enum">
     <xsl:value-of select="concat(., ' ')"/>
  </xsl:for-each>
</xsl:when>

注意: テストされていません (そしてエラーが発生しやすい: 私はxsl:for-each多くの間違いを犯しているため、あまり使用していません)、慎重にテストしてください。

于 2012-09-17T20:17:42.950 に答える