2016-05-09 6 views
0

HTMLレポートを構造化したいので、XMLを以下のように処理します。私は文法の権利を得るのに苦労しています。 変数の外側のcf_fixinpatch値を取得できますが、この値を「選択」で使用してセクションでさらにフィルタリングすることはできません。私は1つが、私はレコードを何を持っているか知っている...おかげXSLTマルチレベルフィルタリングの構文

HTMLを出力

<html> 
<cf_fixinpatch> <= loop through unique values 
    write cf_fixinpatch header 
    <section> <= loop through unique values 
    write section header 
     <All records matching cf_fixinpatch and section values> <= loop 
     Write out various aspects of the Result node 
    </section> 
<cf_fixinpatch> 
</html> 

入力XML

<DocumentElement> 
    <Results> <= many repeat nodes 
    <bug_id>64252</bug_id> 
    <name>SCADA</name> 
    <short_desc>[FUNCTIONALITY]: Server name is not correct in SOE System Message</short_desc> 
    <bug_status>VERIFIED</bug_status> 
    <resolution>FIXED</resolution> 
    <bug_severity>normal</bug_severity> 
    <section>Alarms</section> 
    <release_title>Some SOE items that reference an alarm server do not use its proper name</release_title> 
    <release_notes>Such events now use "ClusterName_ServerName" when referencing alarm servers.</release_notes> 
    <cf_fixinpatch>v7.50 SP1 Patch 5</cf_fixinpatch> 
    </Results> 
    ... 
</DocumentElement> 

NB:Windowsのmsxlを使用して2.0をサポート(とあまりにもハードの場合はありません、2.0に移動することができます)、私は何かをすることができます

<xsl:variable name="unique-list" select="/DocumentElement/Results[not(cf_fixinpatch=following::Results/cf_fixinpatch)]" /> 
<xsl:for-each select="$unique-list"> 
<xsl:variable name="current_patch" select="cf_fixinpatch" /> 
    <!-- but don't know how to use this in the next loop --> 
----------------- 
<xsl:for-each select="/DocumentElement/Results"> 
<xsl:if test="not(section = preceding-sibling::section)"> <= cant get to work, if worked i can win or 
<xsl:if test="cf_fixinpatch != Results[position()-1]/cf_fixinpatch"> 

PM 09/05フィードバック - 私は解決策を見つけましたが、これを行うにはDの方法は、私はあなたがsection要素によって、同じパッチ内のすべての人のため、最初のcf_fixinpatchによると、その後Results要素をグループ化しているように見えますいくつかのフィードバック

<xsl:for-each select="/DocumentElement/Results"> 

     <xsl:variable name="thePatch" select="preceding-sibling::Results[1]/cf_fixinpatch"></xsl:variable> 
     <xsl:if test="($Patches = 'true') and (position() = 1 or cf_fixinpatch != $thePatch)"> 
      <!-- Write out the Patch Level --> 
      <h4 style="color:#d82553"> 
       <a> 
        <xsl:value-of select="cf_fixinpatch" /> 
       </a> 
      </h4> 
     </xsl:if>  

     <xsl:variable name="theSection" select="preceding-sibling::Results[1]/section"></xsl:variable> 

     <xsl:if test="(position() = 1) or (section != $theSection)"> 
      <!-- Write out the Section Information --> 
      <h4 style="color:#C75B12;text-index:40px"> 
       <a> 
       <xsl:value-of select="section" /> 
       </a> 
      </h4> 
     </xsl:if> 

     <!-- Then record info written out --> 
+0

をこれはしばしば問題に近づくための間違った方法です。 XSLTは、(ほぼ)純粋な関数型言語であり、異なるアプローチの恩恵を受ける。 [編集]あなたの質問は、入力に対応する出力XMLを表示し、あなたはいくつかの助けを得る可能性が高いです。 –

+1

'Results'要素を' cf_fixinpatch'値でグループ化しようとすると、XSLT 1.0ではMuenchian Groupingと呼ばれる手法を使います。 (http://www.jenitennison.com/xslt/grouping/muenchian.htmlを参照)。あなたがそのケースであなたの期待される結果を示したら助けになるかもしれません。ありがとうございました! –

+0

私は情報のhtmlファイルを作成していますが、Xmlは入力です。 –

答えて

1

を提供しています。これは、2つのグループ分けをしていることを意味します。ただcf_fixinpatch、グループにあなたが必要となり、このキー

<xsl:key name="results_by_patch" match="Results" use="cf_fixinpatch" /> 

しかし、(文書内のすべてのResultsは対照的に)与えられたグループ内のすべてのResultsの要素のsection値のグループに、あなたが連結キー

が必要になります

<xsl:key name="results_by_patch_and_section" match="Results" use="concat(cf_fixinpatch, '|', section)" /> 

別の内部でグループ化Muenchianの一つのロットネストこのXSLT試してください:あなたはXSLTのprocedを使用しようとしている

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

    <xsl:key name="results_by_patch" match="Results" use="cf_fixinpatch" /> 
    <xsl:key name="results_by_patch_and_section" match="Results" use="concat(cf_fixinpatch, '|', section)" /> 

    <xsl:template match="DocumentElement"> 
    <html> 
     <body> 
     <xsl:for-each select="Results[generate-id() = generate-id(key('results_by_patch', cf_fixinpatch)[1])]"> 
      <h1 style="color:#d82553"> 
      <xsl:value-of select="cf_fixinpatch" /> 
      </h1> 
      <xsl:for-each select="key('results_by_patch', cf_fixinpatch)[generate-id() = generate-id(key('results_by_patch_and_section', concat(cf_fixinpatch, '|', section))[1])]"> 
      <h2 style="color:#C75B12;text-index:40px"> 
       <xsl:value-of select="section" /> 
      </h2> 
      <xsl:apply-templates select="key('results_by_patch_and_section', concat(cf_fixinpatch, '|', section))" /> 
      </xsl:for-each> 
     </xsl:for-each> 
     </body> 
    </html> 
    </xsl:template> 

    <xsl:template match="Results"> 
    <div> 
     <xsl:value-of select="bug_id" /> 
    </div> 
    </xsl:template> 
</xsl:stylesheet> 
関連する問題