2011-05-26 76 views
0

我在Windows上使用Altova的命令行xml處理器來處理幫助& Manual xml文件。幫助&手冊是幫助創作軟件。從嵌入式「para」孩子的「para」標籤中提取文本?

我使用下面的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處提取的。

請注意,我不關心表標籤,我只是想剝去這些。

有沒有辦法構造para規則,以便正確提取para元素的直接擁有文本以及任何子para的文本,以便每個提取的塊在輸出中獲取規則的換行符文本?

回答

0

我想我找到了答案。而不是最後一個para規則的值,我使用apply-templates來代替,並且似乎可以捕獲所有這些。

相關問題