0

これをどのように変更しますか

<CHAPT>
  <CHAPTNO>1.1</CHAPTNO>
  <SUBJ>Introduction</SUBJ>
  <P>foo text</P>
  <P>foo text</P>  .. and so on
</CHAPT>

これに:

<p class="chapheader"><span class="chapnumbers">1.1 </span>Introduction</p>
<P>foo text</P>
<P>foo text</P>

ただし、 ..の直前にある場合<CHAPTNO>にのみ、XML内にaの後に続かないものがあり、それらをチャプターヘッダーとしてフォーマットされたスタンドアロンの件名行にしたくないためです。<SUBJ><SUBJ><CHAPTNO>

私はXSLTを初めて使用し、2番目のテンプレートでスタックしました。

4

1 に答える 1

1

これを試して。これが私のサンプルXMLです(テストのためだけにルート要素を追加しました):

<root>
<CHAPT>
  <CHAPTNO>1.1</CHAPTNO>
  <SUBJ>Introduction1111</SUBJ>
  <P>foo text</P>
  <P>foo text</P>  
</CHAPT>
<CHAPT>
  <SUBJ>Introduction2222</SUBJ>
  <P>foo text</P>
  <P>foo text</P>  
</CHAPT>
<CHAPT>
  <CHAPTNO>3333</CHAPTNO>
  <SUBJ>Introduction3333</SUBJ>
  <P>foo text</P>
  <P>foo text</P>  
</CHAPT>
</root>

XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html" encoding="utf-8" indent="no"/>
 <xsl:template match="/">
        <xsl:for-each select="root/CHAPT">
        <xsl:if test="SUBJ[count(../CHAPTNO)=1]">
           <p class="chapheader"> 
           <span class="chapnumbers"><xsl:value-of select="CHAPTNO"/></span>
                     <xsl:value-of select="SUBJ"/>
             </p>
        </xsl:if>
     </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

結果の出力:

<p class="chapheader"><span class="chapnumbers">1.1</span>Introduction1111</p>
<p class="chapheader"><span class="chapnumbers">3333</span>Introduction3333</p>
于 2013-01-25T22:51:52.230 に答える