2016-12-29 1 views
1

を使用して別のタグに残っている:私の入力XMLファイル<p> </p>別の要素に、私は一つの要素で段落の最初のセットと段落の第2のセットを取りたいつのタグに特定の段落をタグ付けする必要があり、XSLT

私はとして使用
<topic class="- topic/topic " outputclass="TOPIC-MLU-Body"> 
<title outputclass="MLU-Body">Body</title> 
<body class="- topic/body "> 
<p class="- topic/p ">Insulin is a medicine</p> 
<fig class="- topic/fig "> 
<image class="- topic/image " 
      href="SBX0139003.jpg" 
      outputclass="Fig-Image_Ref" placement="break"/> 
<p class="- topic/p " outputclass="Fig-Text">Caption</p> 
</fig> 
<p class="- topic/p ">So, to try and lower your blood glucose levels</p> 
</body> 
</topic> 

XSL:私は段落は、「テキスト・トップ」などの図形要素の前に来て、「text_bottom」などの図形要素の後に必要

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="topic[@outputclass='TOPIC-MLU-Body']"> 
<body> 
<text> 
<text_top><xsl:value-of select="title|body/p"/></text_top> 
<text_bottom><xsl:value-of select="body/fig|p"/></text_bottom> 
</text> 
<xsl:apply-templates/> 
</body> 
</xsl:template> 

</xsl:stylesheet> 

私はのような出力を取得しています:

<mlu9_body> 
    <mlu9_text> 
    <text_top>Insulin is a medicine So, to try and lower your blood glucose levels</text_top> 
    <text_bottom>Caption</text_bottom> 
    </mlu9_text> 
    </mlu9_body> 

しかし、私の予想される出力は次のとおりです。サクソンPEとバージョン= 2.0スタイルシートを使用して

<mlu9_body> 
<mlu9_text> 
<text_top>Insulin is a medicine</text_top> 
<text_bottom>So, to try and lower your blood glucose levels</text_bottom> 
</mlu9_text> 
</mlu9_body> 

イム。私にこの提案をお願いします。前もって感謝します。

答えて

3

あなたが現在取得している出力は、実際に提供したXSLTと実際には一致しません。たとえば、XSLTは<body>タグを出力しますが、出力には<mlu9_body>タグが表示されます。

さらに、XSLTの|演算子は共用演算子であるため、2つのノードセットの和集合が返されます。たとえば、あなたがXSLT 2.0では、この

<xsl:value-of select="body/fig|p"/ 

をやっている、これはbody/figの文字列値との両方p要素の文字列値の連結を返します。とにかく

、あなたの期待される出力を与えるであろう、このXSLTを試してみてください。

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:output method="xml" indent="yes" /> 

<xsl:template match="topic[@outputclass='TOPIC-MLU-Body']"> 
<mlu9_body> 
<mlu9_text> 
<text_top><xsl:value-of select="body/p[1]"/></text_top> 
<text_bottom><xsl:value-of select="body/p[2]"/></text_bottom> 
</mlu9_text> 
</mlu9_body> 
</xsl:template> 

</xsl:stylesheet> 

注意、あなたが本当にfig要素の後に発生したp要素をターゲットしたい場合、あなたはこれを行うことが...

<text_bottom><xsl:value-of select="body/fig/following-sibling::p"/></text_bottom> 
+0

ありがとう@Tim、その働き – User501

関連する問題