2

次のマークアップがあります。

<para><span class="bidi"/><span class="ind"/>1</para>

私はこれを達成しようとしています...

<para><span style="direction:rtl; text-indent:10pt;">1</span></para>

しかし、私はこれを取得しています...

<para><span style="direction:rtl">1</span><span style="text-indent:10pt">1</span></para>

これが私のXSLTです。

  <xsl:template match="span" name="spans">
        <span>
            <xsl:attribute name="style">
        <xsl:choose>                
            <xsl:when test="@class eq 'bidi'">
                <xsl:text>direction:rtl</xsl:text>                
            </xsl:when>
            <xsl:when test="@class eq 'ind'">
                <xsl:text>text-indent:10pt;</xsl:text>                
            </xsl:when>
            <xsl:otherwise/>
        </xsl:choose>
            </xsl:attribute>
            <xsl:apply-templates/>
        </span>
    </xsl:template>

複数のスパンをすべてのクラス属性値で1にマージするにはどうすればよいですか?

4

1 に答える 1

1

この変換:

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

 <xsl:template match="para[span]">
     <para>
       <span>
          <xsl:attribute name="style">
           <xsl:apply-templates select="span"/>
          </xsl:attribute>
          <xsl:apply-templates select="node()[not(self::span)]"/>
       </span>
     </para>
 </xsl:template>

 <xsl:template match="span[@class='bidi']">
  <xsl:if test="position() >1"><xsl:text> </xsl:text></xsl:if>
  <xsl:text>direction:rtl;</xsl:text>
 </xsl:template>

 <xsl:template match="span[@class='ind']">
  <xsl:if test="position() >1"><xsl:text> </xsl:text></xsl:if>
  <xsl:text>text-indent:10pt;</xsl:text>
 </xsl:template>
</xsl:stylesheet>

提供されたXMLドキュメントに適用した場合:

<para><span class="bidi"/><span class="ind"/>1</para>

必要な正しい結果を生成します。

<para><span style="direction:rtl; text-indent:10pt;">1</span></para>
于 2012-07-06T17:54:56.480 に答える