xslt删除p元素

时间:2013-08-30 11:29:40

标签: xslt xslt-1.0

这是我的XML文件。我想导入DESCRIPTION节点标记的内容 在XSLT中没有<P>标记。

<DESCRIPTION>
    <P>A pagina 3, modificare:</P>
    <P>carte per il diporto - Leisure crafts</P>
    <P>in:</P>
    <P>
    <STRONG>Carte Nautiche in Kit - Nautical Charts in </STRONG>
    </P>
</DESCRIPTION> 

XSL:

<xsl:if test="last()&gt;1"> 
<span style=" font-family:Arial; line-height:0; ">
     <xsl:value-of select="concat(position(), &apos;)&apos;)"/>
</span>                         
</xsl:if> 
<xsl:for-each select="NTC_CATALOGUEINSTRUCT"> 
<xsl:for-each select="DESCRIPTION">
    <span style="text-align:justify; margin-bottom:0pt">
        <xsl:apply-templates/>                              </span>   
     </xsl:for-each>                    
</xsl:for-each> 

此XML的输出---&gt; XSL文件是:

1)
    A pagina 3, modificare:
    carte per il diporto - Leisure crafts     charts...............................................51
    in:
    Carte Nautiche in Kit - Nautical Charts in Kit.........................................51

我想:

1) A pagina 3, modificare: <------((((( look in the same line ))))))
carte per il diporto - Leisure crafts        charts...............................................51
    in:
    Carte Nautiche in Kit - Nautical Charts in Kit.........................................51

1 个答案:

答案 0 :(得分:1)

这个XSLT样式表:

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

  <!-- The identity transform. -->
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <!-- Don't copy P elements themselves but do output their contents. 
       Enumerate the descriptions. -->
  <xsl:template match="P">
    <xsl:if test="count(preceding-sibling::P) = 0">
      <xsl:value-of select="count(../preceding-sibling::DESCRIPTION) + 1"/>
      <xsl:text>) </xsl:text>
    </xsl:if>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:template>

</xsl:stylesheet>

应用于输入XML时:

<DESCRIPTION>
  <P>A pagina 3, modificare:</P>
  <P>carte per il diporto - Leisure crafts</P>
  <P>in:</P>
  <P>
    <STRONG>Carte Nautiche in Kit - Nautical Charts in </STRONG>
  </P>
</DESCRIPTION>

产生以下输出:

  1) A pagina 3, modificare:
  carte per il diporto - Leisure crafts
  in:

    Carte Nautiche in Kit - Nautical Charts in 

认为就是你想要的。