0

xsl 内から親要素のテキストを変更しようとしています。どうすれば削除できますか

XSL コードの要素 (入力は制御しません)。本文のすべての改行ではなく、前の改行のみを削除したい。前述の「some text here」は、複数の段落の形式をとる場合があります。

Xsl

<xsl:template match="element">
  <!-- attempting to add fix here -->

  <xsl:apply-templates />
</xsl:template>

入力

<body>
  <p>
    some text here
  </p>
  <element>
    some more text
  </element>
</body>

出力

some text here
some more text

望ましい出力

some text here some more text
4

1 に答える 1

1

する

<xsl:template match="p[following-sibling::*[1][self::element]]//text() | element[preceding-sibling::*[1][self::p]//text()">
  <xsl:value-of select="normalize-space()"/>
</xsl:template>

あなたがしたいことをしますか?

<xsl:template match="element"><xsl:apply-templates/></xsl:template>とにかく組み込みのテンプレートがそれを行うので、必要はありません。

コードをテストする時間を見つけました。

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

<xsl:output method="text"/>

<xsl:template match="p[following-sibling::*[1][self::element]]//text() |
  element[preceding-sibling::*[1][self::p]]//text()">
  <xsl:value-of select="normalize-space()"/>
</xsl:template>

<xsl:template match="text()[preceding-sibling::*[1][self::p] and following-sibling::*[1][self::element] and not(normalize-space())]">
  <xsl:text> </xsl:text>
</xsl:template>

</xsl:stylesheet>

変形する

<body>
  <p>
    some text here
  </p>
  <element>
    some more text
  </element>
</body>

の中へ

  some text here some more text
于 2012-09-14T17:04:38.070 に答える