0

要素にテキストが散在する他の要素が含まれている場合、テキスト要素の順序を維持するにはどうすればよいですか? この (簡略化された) 例では:

  <block>1st text<bsub>2nd text</bsub>3rd text</block>

目的の出力は次のとおりです。

  "1st text 2nd text 3rd text"

私が試してみました:

  <xsl:template match="block">
    <xsl:value-of select=".">
    <xsl:apply-templates select="bsub"/>
    <xsl:value-of select=".">
  </xsl:template>

  <xsl:template match="bsub">  
    <xsl:value-of select=".">
  </xsl:template>

そしてそれは出力します:

  "1st text 2nd text 3rd text 2nd text 1st text 2nd text 3rd text"

<block>を使用して (の)個々のテキスト要素を選択する方法は<xsl:value-of>?

4

2 に答える 2

0

この XSLT 1.0 スタイルシート...

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

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

<xsl:template match="block|bsub">
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="text()">
  <xsl:value-of select="concat(.,' ')" />
</xsl:template>

</xsl:stylesheet>

...入力ドキュメントに適用すると...

<block>1st text<bsub>2nd text</bsub>3rd text</block>

...収量...

<t>1st text 2nd text 3rd text </t>
于 2012-08-30T03:44:16.530 に答える
0

このような混合コンテンツの処理に value-of を使用しないでください。代わりに apply-templates を使用すると、すべてうまくいきます。

于 2012-08-30T02:58:19.553 に答える