从嵌入式“para”孩子的“para”标签中提取文字?

时间:2011-05-26 14:30:02

标签: xslt

我在Windows上使用Altova的命令行xml处理器来处理帮助&手动xml文件。帮助&手册是帮助创作软件。

我正在使用以下xslt从中提取文本内容。具体来说,我遇到了最终的参数规则问题:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" />
  <xsl:strip-space elements="*" />
  <xsl:template match="para[@styleclass='Heading1']">
    <xsl:text>====== </xsl:text>
    <xsl:value-of select="." />
    <xsl:text> ======&#xA;&#xA;</xsl:text>
  </xsl:template>
  <xsl:template match="para[@styleclass='Heading2']">
    <xsl:text>===== </xsl:text>
    <xsl:value-of select="." />
    <xsl:text> =====&#xA;&#xA;</xsl:text>
  </xsl:template>
  <xsl:template match="para">
    <xsl:value-of select="." />
    <xsl:text>&#xA;&#xA;</xsl:text>
  </xsl:template>
  <xsl:template match="toggle">
    <xsl:text>**</xsl:text>
    <xsl:apply-templates />
    <xsl:text>**&#xA;&#xA;</xsl:text>
  </xsl:template>
  <xsl:template match="title" />
  <xsl:template match="topic">
    <xsl:apply-templates select="body" />
  </xsl:template>
  <xsl:template match="body">
    <xsl:text>Content-Type: text/x-zim-wiki&#xA;Wiki-Format: zim 0.4&#xA;&#xA;</xsl:text>
    <xsl:apply-templates />
  </xsl:template>
</xsl:stylesheet>

我遇到了从某些段落元素中提取文本的问题。以xml:

为例
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?>
<topic template="Default" lasteditedby="tlilley" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd">
  <title translate="true">New Installs</title>
  <keywords>
    <keyword translate="true">Regional and Language Options</keyword>
  </keywords>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">New Installs</text></para>
    </header>
    <para styleclass="Normal"><table rowcount="1" colcount="2" style="width:100%; cell-padding:6px; cell-spacing:0px; page-break-inside:auto; border-width:1px; border-spacing:0px; cell-border-width:0px; border-color:#000000; border-style:solid; background-color:#fffff0; head-row-background-color:none; alt-row-background-color:none;">
      <tr style="vertical-align:top">
        <td style="vertical-align:middle; width:96px; height:103px;">
          <para styleclass="Normal" style="text-align:center;"><image src="books.png" scale="100.00%" styleclass="Image Caption"></image></para>
        </td>
        <td style="vertical-align:middle; width:1189px; height:103px;">
          <para styleclass="Callouts"><text styleclass="Callouts" style="font-weight:bold;" translate="true">Documentation Convention</text></para>
          <para styleclass="Callouts"><text styleclass="Callouts" translate="true">To make the examples concrete, we refer to the </text><var styleclass="Callouts">Add2Exchange</var><text styleclass="Callouts" translate="true"> Service Account as &quot;zAdd2Exchange&quot; throughout this document.  If your Service Account name is different, substitute that value for &quot;zAdd2Exchange&quot; in all commands and examples.  If you have named your account according to the recommended &quot;zAdd2Exchange&quot;, then you may cut and paste any given commands as is.</text></para>
        </td>
      </tr>
    </table></para>
  </body>
</topic>

当xslt在该段落上运行时,它将文本拉出,但在顶部段落元素中执行此操作。转换应该为所有提取的段落添加一对换行符,但是没有机会对嵌入的<para>元素执行此操作,因为文本是在父para元素处提取的。 / p>

请注意,我不关心表格标签,我只想剥离它们。

有没有办法构造para规则,以便它正确地提取para元素的直接拥有的文本,以及任何子para的文本,这样每个提取的块在输出文本中获取规则的换行符?

1 个答案:

答案 0 :(得分:0)

我想我找到了答案。而不是使用最后一个参数规则的值,而是使用apply-templates,而这似乎抓住了它们。

相关问题