0

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

<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 ---> 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
4

1 回答 1

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 

认为这就是你想要的。

于 2013-08-30T12:12:01.220 回答