2

一体何なの?

次の操作を実行する xslt ファイルを作成する必要があります。全体の話は法律についてです。法改正で何が起こっているかを考えてみてください。あなたは古い法律 X を持っており、立法者は法律 X を参照する修正を含む新しい法律 Y をもたらします。修正は、法律のあらゆる種類の下位部分 (節、記事、段落など) を置き換えることができます。


ローX

第1条

  1. ここに本当に古いものがあります
  2. 何とか何とか何とか

第2条 [....]


Y法

第1条

  1. 何とか何とか何とか

第2条

  1. 法律 Y の第 1 条の第 1 段落を次のように置き換えます。

そして、あなたが本当に知りたいことは何ですか?


法則 X'

第1条

  1. 新鮮で素晴らしいもの
  2. 何とか何とか何とか

第2条 [....]


XML立法の世界に移りましょう

このようなXMLファイルXがあります

<Legislation DocumentURI="X">
<Metadata>[...]</Metadata>
<Introduction>[...]</Introduction>
<Body>
<Article DocumentURI="X/article/1">
<P DocumentURI="X/article/1/paragraph/1">
   <P2 DocumentURI="X/article/1/paragraph/1/passage/1">
            <Text>SOMETHING REALLY OLD HERE</Text>
   </P2>
</P>
<P DocumentURI="X/article/1/paragraph/2">
   <P2 DocumentURI="X/article/1/paragraph/2/passage/1">
            <Text>blahblahblah</Text>
   </P2>
</P>
</Article>
</Body>
</Legislation>

このようなXMLファイルYがあります

<Legislation DocumentURI="Y">
<Metadata>[...]</Metadata>
<Introduction>[...]</Introduction>
<Body>
<Article DocumentURI="Y/article/1">
<P DocumentURI="Y/article/1/paragraph/1">
   <P2 DocumentURI="Y/article/1/paragraph/1/passage/1">
            <Text>blahblahblah</Text>
   </P2>
</P>
</Article>
<Article DocumentURI="Y/article/2">
<P DocumentURI="Y/article/2/paragraph/1">
   <P2 DocumentURI="Y/article/2/paragraph/1/passage/1">
            <Text>Replace the 1st paragraph of the 1st article in Law Y as:</Text>
   </P2>
   <Modification DocumentURI="Y/modification/1">
     <P2 URI="X/article/1/paragraph/1/passage/1">
        <Text>SOMETHING FRESH ANS AWESOME</Text>
     </P2>
   </Modification>
</P>
</Article>
</Body>
</Legislation>

そして、X' を生成します。

<Legislation DocumentURI="X">
<Metadata>[...]</Metadata>
<Introduction>[...]</Introduction>
<Body>
<Article DocumentURI="X/article/1">
<P DocumentURI="X/article/1/paragraph/1">
   <P2 DocumentURI="X/article/1/paragraph/1/passage/1">
            <Text>SOMETHING FRESH AND AWESOME</Text>
   </P2>
</P>
<P DocumentURI="X/article/1/paragraph/2">
   <P2 DocumentURI="X/article/1/paragraph/2/passage/1">
            <Text>blahblahblah</Text>
   </P2>
</P>
</Article>
</Body>
</Legislation>

ヒント: <Modification>コンテンツは、あらゆる種類の法律の一部である可能性があります。上記のような単一の XML 要素かもしれませんし、記事全体のようなネストされたノード全体かもしれません!

ヒント 2:<Modification>同じ要素が 1 回しか発生しないと誰が言いましたか? おそらく、2012 年に法律 Y が特定の部分を変更し、2013 年に新しい法律 Z が、既に変更された部分を別の方法で変更するか、この部分の下位部分を変更します!

ヒント 3:<Modification>ファイル X に既にある要素を参照していると誰が言いましたか? たぶん、法律 Y は、古い法律 X に新しい部分を追加します!

変更がどこにあるのかをどのように知ることができますか?

  1. それらの DocumentURI 属性値はわかっています。
  2. それらが立っているXMLファイルを知っています。

XSLT を使用する前に、アクション (findmodifications) が呼び出されます。このアクションでは、法律の ID を表す URL のワイルドカード (*) を使用し、rdfstore で変更を検索します。最後に、modification と呼ばれるリクエスト パラメータを設定して、結果を返します。

変更のパラメーターには、次の構造があります。

modification[0][0] = PD201210.xml  
modification[0][1] = http://localhost:8888/GRLegislation/pd/2012/10/modification/1  
modification[1][0] = PD201210.xml  
modification[1][1] = http://localhost:8888/GRLegislation/pd/2012/10/modification/2  
.  
.  
.

結局、変更された XML コンテンツ X' で何をしたいのでしょうか?

私は Web アプリケーション プロジェクトに Apache Cocoon Framework を使用しているため、サイトマップに特定のパイプラインがあります。このパイプラインは、変更箇所を見つけるためにアクションを呼び出し、X ファイルを取得して xslt 変換を実行し、HTML としてシリアル化します。

<map:pipeline id="law-updated">
      <map:match pattern="pd/*/updated">
        <map:act type="findmodifications">      
        </map:act>
        <map:generate src="{1}.xml" type="file"/>
        <map:transform src="legislation_updated.xslt" type="xslt"/>
        <map:serialize type="xhtml"/>
      </map:match>
</map:pipeline>

HTML 変換用の XSLT テンプレートは次のとおりです。

<xsl:template match="/">
    <html>
        <head>
        </head>
        <body>
            <div id="wrapper">
                <div id="header">
                        ............
                </div>
                <div id="content">
                    <div id="content_column">
                        <div class="button" >
                            <a>
                                <xsl:attribute name="href">
                                    <xsl:value-of select="Legislation/Metadata/dc:identifier"/>/data.rdf
                                </xsl:attribute>RDF</a>
                        </div><br/><br/>
                        <div class="button" >
                            <a style="color: #fff;">
                                <xsl:attribute name="href">
                                    <xsl:value-of select="Legislation/Metadata/dc:identifier"/>/data.pdf
                                </xsl:attribute>PDF</a>
                        </div><br/>

                    </div>
                    <div id="content_body">
                        <div id="content_text">
                          <div id="content_bar">
                                 <ul>
                                    <li style="font-size: 16px; font-weight: bold; float:left; padding-right:2em;">
                                        <a><xsl:attribute name="href">
                                            <xsl:value-of select="Legislation/Metadata/dc:identifier"/>/contents
                                        </xsl:attribute>Περιεχόμενα</a>
                                    </li>
                                    <li style="font-size: 16px; font-weight: bold; float:left; padding-right:2em;">
                                        <a><xsl:attribute name="href">
                                            <xsl:value-of select="Legislation/Metadata/dc:identifier"/>
                                        </xsl:attribute>Κείμενο</a>
                                    </li>
                                    <li style="font-size: 16px; font-weight: bold; float:left; padding-right:2em;">
                                        <a><xsl:attribute name="href">
                                            <xsl:value-of select="Legislation/Metadata/dc:identifier"/>/timeline
                                        </xsl:attribute>Χρονολόγιο</a>
                                    </li>
                                    <li style="font-size: 16px; font-weight: bold; float:left; padding-right:2em;">
                                        <a><xsl:attribute name="href">
                                            <xsl:value-of select="Legislation/Metadata/dc:identifier"/>/citations
                                        </xsl:attribute>Παραπομπές</a>
                                    </li>
                                </ul>
                                </div>
                                <br/>
                                <br/>
                        <table border="0">
                        <tr><td>ΦΕΚ:&#160;</td> 
                            <td><xsl:value-of select="Legislation/Metadata/diavgeia:fek/issue"/>
                        / <xsl:value-of select="Legislation/Metadata/diavgeia:fek/year"/>
                        / <xsl:value-of select="Legislation/Metadata/diavgeia:fek/fekNumber"/>
                        </td></tr>
                        <tr>
                            <td>ΚΩΔΙΚΟΣ ΑΠΟΦΑΣΗΣ:&#160;</td>
                            <td> <xsl:value-of select="Legislation/Metadata/diavgeia:decisionType/diavgeia:label"/>
                            &#160; <xsl:value-of select="Legislation/Metadata/Year"/>
                            / <xsl:value-of select="Legislation/Metadata/Number"/>
                            </td>
                        </tr>
                        <tr>
                            <td>ΗΜΕΡΟΜΗΝΙΑ ΕΚΔΟΣΗΣ:&#160;</td> 
                            <td>
                                <xsl:value-of select="Legislation/Metadata/dc:created"/>

                            </td>

                        </tr>
                        <tr>
                            <td>ΥΠΟΓΡΑΦΗ:&#160;</td> 
                            <td>
                                <xsl:for-each select="Legislation/Metadata/diavgeia:signer">
                                <a><xsl:attribute name="href">http://localhost:8888/GRLegislation/signer/<xsl:value-of select="@uid"/></xsl:attribute>
                                <xsl:value-of select="diavgeia:firstName"/>&#160;
                                <xsl:value-of select="diavgeia:lastName"/>
                                </a>
                                <xsl:choose>
                                <xsl:when test="position() != last()">,&#160;</xsl:when>
                                </xsl:choose>
                                </xsl:for-each>
                            </td>

                        </tr>
                         <tr>
                            <td>ΣΧΕΤΙΚΑ ΜΕ:&#160;</td> 
                            <td>
                                <xsl:for-each select="Legislation/Metadata/diavgeia:tag">
                                <xsl:value-of select="diavgeia:label"/>
                                <xsl:choose>
                                <xsl:when test="position() != last()">,&#160;</xsl:when>
                                </xsl:choose>
                               </xsl:for-each>
                            </td>

                        </tr>
                        </table>
                        <br/>
                        <h4>
                            <xsl:value-of select="Legislation/Metadata/dc:title"/>
                        </h4>

                                                 <br/>
                                                 <xsl:for-each select="Legislation/Body/Article">
                                                    <div><xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
                                                    <p>
                                                        <h5>Άρθρο
                                                            <xsl:value-of select="Number"/>
                                                        </h5>
                                                        <xsl:if test="Title">
                                                        <h6>
                                                            <xsl:value-of select="Title"/>
                                                         </h6>
                                                         </xsl:if>
                                                        <br/>
                                                        <ol>
                                                        <xsl:for-each select="P">
                                                            <div><xsl:attribute name="id">
                                                                <xsl:value-of select="@DocumentURI"/>
                                                                </xsl:attribute>
                                                            <li>
                                                             <xsl:for-each select="P2">
                                                                 <xsl:value-of select="Text"/>&#160;
                                                             </xsl:for-each>
                                                             <xsl:for-each select="List">
                                                                 <ol style="list-style-type:lower-greek">
                                                                 <xsl:for-each select="Case">
                                                                     <li>
                                                                         <xsl:value-of select="Text"/>
                                                                     </li>
                                                                 </xsl:for-each>
                                                                 </ol>
                                                             </xsl:for-each>
                                                             <xsl:for-each select="Modification">

                                                                <div id="modification" >
                                                                 <xsl:if test="P">
                                                                    <ol>
                                                                    <xsl:for-each select="P">
                                                                        <li>
                                                                            <xsl:attribute name="value">
                                                                            <xsl:value-of select="Number"/>
                                                                            </xsl:attribute>
                                                                         <xsl:for-each select="P2">
                                                                             <xsl:value-of select="Text"/>&#160;
                                                                         </xsl:for-each>
                                                                         <xsl:for-each select="List">
                                                                             <ol style="list-style-type:lower-greek">
                                                                             <xsl:for-each select="Case">
                                                                                 <li>
                                                                                     <xsl:value-of select="Text"/>
                                                                                 </li>
                                                                             </xsl:for-each>
                                                                             </ol>
                                                                         </xsl:for-each>
                                                                        </li> 
                                                                    </xsl:for-each>
                                                                    </ol>
                                                                 </xsl:if>
                                                                 <xsl:if test="P2">
                                                                        <xsl:for-each select="P2">
                                                                        <xsl:value-of select="Text"/>&#160;
                                                                        </xsl:for-each>
                                                                 </xsl:if>
                                                                 <xsl:if test="Case">
                                                                     <ol>   
                                                                    <xsl:for-each select="Case">
                                                                     <li><xsl:attribute name="value">
                                                                            <xsl:value-of select="Value"/>
                                                                            </xsl:attribute>
                                                                         <xsl:value-of select="Text"/>
                                                                     </li>
                                                                    </xsl:for-each>
                                                                     </ol>
                                                                 </xsl:if>
                                                                </div>
                                                             </xsl:for-each>
                                                            </li> 
                                                            </div>                                                           
                                                        </xsl:for-each>
                                                        </ol>
                                                    </p>
                                                    </div>
                                                 </xsl:for-each>
                    </div>
                    </div>
                </div>
        </body>
    </html>
  </xsl:template>

追加情報が必要な場合は、お尋ねください。実際の XML X ファイルはここにあります。X に変更を加えた実際の XML Y ファイルは、ここにあります。変更された XML は次のようになります

修正タイプ:

  1. 実際の XML ファイル Y の変更 2、3、4 のようなノードの置換。
  2. 実際の XML ファイル Z の変更 1 のようなノードの追加。
  3. ノードの削除。削除の変更が空のノードの構造を持つとしましょう。お気に入り<Modification DocumentURI=""><P2 DocumentURI=""></P2></Modification>
4

2 に答える 2

1

数日後、質問の最後の部分で、完全に偶発的な解決策を見つけました。2 つの異なる XSLT スタイルシートがあります。

  • 1 つは HTML 表現用 (上記の質問を参照)、および
  • 変更を処理するTomalakからの上記のスタイルシート (回答を参照)

前述したように、X XML ファイルの変更を調整してから、変更した X' を HTML で公開する必要がありました。したがって、Apache Cocoon は、次の 2 つの手順を実装する機会を提供します。

<map:pipeline id="law-updated">
      <map:match pattern="pd/*/updated">
        <map:act type="findmodifications">      
        </map:act>
        <map:generate src="{1}.xml" type="file"/>
        <!-- Tomalak stylesheet -->
        <map:transform src="legislation_updated.xslt" type="xslt"/>
        <!-- HTML stylesheet -->
        <map:transform src="html.xslt" type="xslt"/>
        <map:serialize type="xhtml"/>
      </map:match>
</map:pipeline>

それと同じくらい簡単ですが、ドキュメントのどこにも言及されていません。

残りの問題: XSLT を使用する前に、アクション (findmodifications) が呼び出されます。このアクションでは、法律の ID を表す URL のワイルドカード (*) を使用し、rdfstore で変更を検索します。最後に、modification と呼ばれるリクエスト パラメータを設定して、結果を返します。

Tomalak のスタイルシートでは、変更はインラインで行われます (最初の 5 行を参照)。request パラメータを使用します。

変更のパラメーターには、次の構造があります。

modification[0][0] = PD201210.xml  
modification[0][1] = http://localhost:8888/GRLegislation/pd/2012/10/modification/1  
modification[1][0] = PD201210.xml  
modification[1][1] = http://localhost:8888/GRLegislation/pd/2012/10/modification/2  
.  
.  
.
于 2014-01-29T13:31:23.407 に答える
1

これがあなたを始めるかもしれないスタイルシートです。

あるドキュメント (「古い状態」) を別のドキュメント (「新しい状態」) にマージするように設計されています。

  • ドキュメントのヘッダー/メタデータには触れません。これは「古い状態」から取得されます。他のものを使用したい場合は、適切な<xsl:template match="Metadata">などを書いてください。
  • 「古い状態」のすべてのノードを通過します。<Modification>「古い状態」のノードを参照する「新しい状態」の がある場合、変更の内容がコピーされます。
  • それ以外の場合は、古い状態がコピーされます。
  • 「新しい状態」からのすべての追加は、既存のものに追加されると想定しています。そうでなければ、それらは単に変更になるからですよね?
  • パラメータベースです。複数の変更を適用する場合は、前の実行の出力を次の入力として使用して、段階的に適用します。

実際の XML ファイルとサンプルでテストしました。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes" />

  <xsl:param name="modificationsDoc" select="''" />

  <xsl:variable name="existingURIs" select="//@DocumentURI" />
  <xsl:variable name="mods" select="document($modificationsDoc)//Modification/*" />

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

  <!-- only elements with DocumentURI can be target of modifications -->
  <xsl:template match="*[@DocumentURI]">
    <xsl:variable name="currURI" select="@DocumentURI" />
    <xsl:variable name="matchingMod" select="$mods[@DocumentURI = $currURI]" />

    <!-- replacements and deletions -->
    <xsl:choose>
      <xsl:when test="$matchingMod">
        <!-- no output for empty modifications (they are deletions) -->
        <xsl:if test="$matchingMod[*]">
          <xsl:copy-of select="$matchingMod" />
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="identity" />
      </xsl:otherwise>
    </xsl:choose>

    <!-- additions -->
    <xsl:variable name="siblingURI">
      <xsl:call-template name="substring-before-last">
        <xsl:with-param name="string1" select="$currURI" />
        <xsl:with-param name="string2" select="'/'" />
      </xsl:call-template>
      <xsl:text>/</xsl:text>
    </xsl:variable>
    <xsl:copy-of select="$mods[
      number(substring-after(@DocumentURI, $siblingURI)) &gt; 0
      and not(@DocumentURI = $existingURIs)
    ]" />
  </xsl:template>

  <xsl:template name="substring-before-last">
    <xsl:param name="string1" select="''" />
    <xsl:param name="string2" select="''" />

    <xsl:if test="$string1 != '' and $string2 != ''">
      <xsl:variable name="head" select="substring-before($string1, $string2)" />
      <xsl:variable name="tail" select="substring-after($string1, $string2)" />
      <xsl:value-of select="$head" />
      <xsl:if test="contains($tail, $string2)">
        <xsl:value-of select="$string2" />
        <xsl:call-template name="substring-before-last">
          <xsl:with-param name="string1" select="$tail" />
          <xsl:with-param name="string2" select="$string2" />
        </xsl:call-template>
      </xsl:if>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>

サンプル XML を使用すると、出力は次のようになります。

<Legislation DocumentURI="X">
  <Metadata>[...]</Metadata>
  <Introduction>[...]</Introduction>
  <Body>
    <Article DocumentURI="X/article/1">
      <P DocumentURI="X/article/1/paragraph/1">
        <P2 DocumentURI="X/article/1/paragraph/1/passage/1">
          <Text>SOMETHING FRESH ANS AWESOME</Text>
        </P2>
      </P>
      <P DocumentURI="X/article/1/paragraph/2">
        <P2 DocumentURI="X/article/1/paragraph/2/passage/1">
          <Text>blahblahblah</Text>
        </P2>
      </P>
    </Article>
  </Body>
</Legislation>

ノート:

  • substring-before-lastテンプレートは私の以前の回答からのものです。
于 2014-01-22T19:44:39.130 に答える