2017-08-16 2 views
1

私は、リストパラ内アイテムと、脚注テキスト内のサブリストを追加したいクロージングパラ内部の決算パラとアイテムと、脚注の間にサブリストを追加する必要があります。

マイソースのxml:

<body> 
<p>blahblah</p> 
<ul outputclass="l1"> 
<li outputclass="lt1">blahblah</li> 
<li outputclass="lt1">blahblah</li> 
<li outputclass="lt1">blahblah 
    <ul outputclass="l2"> 
    <li outputclass="lt2">blahblah</li> 
    <li outputclass="lt2">blahblah<fn><p>blah</p></fn></li> 
    <li outputclass="lt2">blahblah 
    <ul outputclass="l3"> 
    <li outputclass="lt3">blahblah<fn><p>blah</p></fn></li> 
    <li outputclass="lt3">blah<fn><p>blah</p></fn>blah</li> 
    <li outputclass="lt3">blahblah</li> 
    </ul></li> 
    </ul></li> 
<li outputclass="lt1">blahblah</li> 
<li outputclass="lt1">blahblah</li> 
</ul> 
<p>blahblah</p> 
</body> 

myxslt

私はサブリストの後にパラ終値として必要なサブリストの最後にパラ閉鎖を取得しています
<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    exclude-result-prefixes="xs" 
    version="2.0"> 

    <xsl:template match="p"> 
     <para> 
      <xsl:apply-templates/> 
     </para> 
    </xsl:template> 

    <xsl:template match="ul[@outputclass='l1']"> 
     <itemizedlist type="&#x2022;"> 
      <xsl:apply-templates/> 
     </itemizedlist> 
    </xsl:template> 

    <xsl:template match="ul[@outputclass='l2']"> 
     <itemizedlist type="&#x2022;"> 
      <xsl:apply-templates/> 
     </itemizedlist> 
    </xsl:template> 

    <xsl:template match="ul[@outputclass='l3']"> 
     <itemizedlist type="&#x2022;"> 
      <xsl:apply-templates/> 
     </itemizedlist> 
    </xsl:template> 

    <xsl:template match="li[@outputclass='lt1']"> 
     <item> 
      <xsl:apply-templates/> 
     </item> 
    </xsl:template> 

    <xsl:template match="li[@outputclass='lt2']"> 
     <item> 
      <xsl:apply-templates/> 
     </item> 
    </xsl:template> 

    <xsl:template match="li[@outputclass='lt3']"> 
     <item> 
      <xsl:apply-templates/> 
     </item> 
    </xsl:template> 

    <xsl:template match="li/text()[normalize-space()]"> 
     <para> 
      <xsl:value-of select="."/> 
     </para> 
    </xsl:template> 

</xsl:stylesheet> 

出力:

<body> 
<para>blahblah</para> 
<itemizedlist type="&#x2022;"> 
<item><para>blahblah</para></item> 
<item><para>blahblah</para></item> 
<item><para>blahblah</para> 
    <itemizedlist type="&#x2022;"> 
    <item><para>blahblah</para></item> 
    <item><para>blahblah</para><footnote><para>blah</para></footnote></item> 
    <item><para>blahblah</para> 
    <itemizedlist type="&#x2022;"> 
    <item><para>blahblah</para><footnote><para>blah</para></footnote></item> 
    **<item><para>blah</para><footnote><para>blah</para></footnote><para>blah</para></item>** 
    <item><para>blahblah</para></item> 
    </itemizedlist></item> 
    </itemizedlist></item> 
<item><para>blahblah</para></item> 
<item><para>blahblah</para></item> 
</itemizedlist> 
<para>blahblah</para> 
</body> 

が、以下に示すようにサブリストは、アイテムパラ内部パラ閉鎖とアイテム閉鎖と脚注の間であるべきなどの必要な出力:1を太字として

<body> 
<para>blahblah</para> 
<itemizedlist type="&#x2022;"> 
<item><para>blahblah</para></item> 
<item><para>blahblah</para></item> 
**<item><para>blahblah</para>** 
    <itemizedlist type="&#x2022;"> 
    <item><para>blahblah</para></item> 
    <item><para>blahblah</para></item> 
    **<item><para>blahblah<footnote><para>blah</para></footnote></para>** 
    <itemizedlist type="&#x2022;"> 
    <item><para>blahblah<footnote><para>blah</para></footnote></para></item> 
    **<item><para>blah<footnote><para>blah</para></footnote>blah</para></item>** 
    <item><para>blahblah</para></item> 
    **</itemizedlist></item>** 
    **</itemizedlist></item>** 
<item><para>blahblah</para></item> 
<item><para>blahblah</para></item> 
</itemizedlist> 
<para>blahblah</para> 
</body> 

ことが可能です。 可能であれば、私に連絡してください

ありがとうございました。あなたは本当にparaにノードをラップする基準である説明されていない

答えて

0

、ここで任意の隣接ノードがpara要素にul要素されていないラップするfor-each-group group-adjacent="boolean(self::ul)"を使用したサンプルです:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    exclude-result-prefixes="xs" 
    version="2.0"> 

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

    <xsl:template match="p"> 
     <para> 
      <xsl:apply-templates/> 
     </para> 
    </xsl:template> 

    <xsl:template match="ul[@outputclass='l1'] | ul[@outputclass='l2'] | ul[@outputclass='l3']"> 
     <itemizedlist type="&#x2022;"> 
      <xsl:apply-templates/> 
     </itemizedlist> 
    </xsl:template> 

    <xsl:template match="li[@outputclass='lt1'] | li[@outputclass='lt2'] | li[@outputclass='lt3']"> 
     <item> 
      <xsl:for-each-group select="node()" group-adjacent="boolean(self::ul)"> 
       <xsl:choose> 
        <xsl:when test="current-grouping-key()"> 
         <xsl:apply-templates select="current-group()"/> 
        </xsl:when> 
        <xsl:otherwise> 
         <para> 
          <xsl:apply-templates select="current-group()" mode="preserve"/> 
         </para> 
        </xsl:otherwise> 
       </xsl:choose> 
      </xsl:for-each-group> 
     </item> 
    </xsl:template> 

</xsl:stylesheet> 
+0

はHonnen @Martinありがとうその働き – User515