首页 > 解决方案 > 如何将新的 XSLT 转换应用于前一个的输出 - 列表之间存在奇数间距的问题?

问题描述

我对 XSLT 完全陌生,所以不要介意我询问基本的事情。我需要准备一个将发送到 Adob​​e InDesign 服务器的 xml。在 html 文件(代表我需要转换为 xml 并使用 XSLT 转换发送到 Adob​​e InDesign 的输入)中,我有以下列表:

<ul> 
  <li>Two potential pathophysiologic conditions lead to the clinical findings of HF, namely systolic and/or diastolic heart dysfunction. 
      <ul> 
           <li>Systolic dysfunction: an&#xa0;<i>inotropic</i>&#xa0;abnormality, due to myocardial infarction (MI) or dilated or ischemic cardiomyopathy (CM), resulting in diminished systolic emptying (ejection fraction &lt;45%).</li> 
           <li>Diastolic dysfunction: a&#xa0;<i>compliance</i>&#xa0;abnormality, due to hypertensive CM, in which ventricular relaxation is impaired (ejection fraction &gt;45%), resulting in decreased filling.</li> 
           <li>In an attempt to adopt a more pragmatic classification system, one that has been accepted by both the European and American HF guidelines, the terms HF with reduced, midrange, or preserved LVEF (HFrEF, HFmrEF, and HFpEF, respectively) have been adopted recently.</li> 
      </ul> </li> </ul>

我用于转换的主要模板是:

<xsl:template match="li[not(descendant::p) and not(ancestor::section[@class='references' or @class='References'])]" mode="li-pass1">    
       <xsl:variable name="depth" select="count(ancestor::li) + 1"/>
    
    <xsl:variable name="listType">
      <xsl:choose>
        <xsl:when test="parent::ol">
          <xsl:value-of select="'NL'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="'BL'"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    
      <ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/{$listType}{if ($depth eq 1) then '' else $depth}">
      <Content>      
      <xsl:copy-of select="./text() | descendant::span/text() | descendant::i/text()"/>
      </Content>
      <Br/>     
      </ParagraphStyleRange>
    </xsl:template>

我得到以下输出,在 BL 和 BL2 之间有不需要的间距:

<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/BL">
     <CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">
            <Content>Two potential pathophysiologic conditions lead to the clinical findings of HF, namely systolic and/or diastolic heart dysfunction. 
              inotropiccompliance</Content>
                <Br/>
     </CharacterStyleRange>
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/BL2">
     <CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">
           <Content>Systolic dysfunction: an inotropic abnormality, due to myocardial infarction MI) or dilated or ischemic cardiomyopathy (CM), resulting in diminished systolic emptying (ejection fraction &lt;45%).</Content>
           <Br/>
     </CharacterStyleRange>
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/BL2">
     <CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">
         <Content>Diastolic dysfunction: a compliance abnormality, due to hypertensive CM, in which ventricular relaxation is impaired (ejection fraction &gt;45%), resulting in decreased filling.</Content>
      <Br/>
    </CharacterStyleRange>

我应该在 xml 中得到以下输出:

<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/BL">
     <CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">
            <Content>Two potential pathophysiologic conditions lead to the clinical findings of HF, namely systolic and/or diastolic heart dysfunction.</Content>
                <Br/>
     </CharacterStyleRange>
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/BL2">
     <CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">
           <Content>Systolic dysfunction: an inotropic abnormality, due to myocardial infarction MI) or dilated or ischemic cardiomyopathy (CM), resulting in diminished systolic emptying (ejection fraction &lt;45%).</Content>
           <Br/>
     </CharacterStyleRange>
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/BL2">
     <CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">
         <Content>Diastolic dysfunction: a compliance abnormality, due to hypertensive CM, in which ventricular relaxation is impaired (ejection fraction &gt;45%), resulting in decreased filling.</Content>
      <Br/>
    </CharacterStyleRange>

因此,以下行(取自输出)实际上是我的问题:

<Content>Two potential pathophysiologic conditions lead to the clinical findings of HF, namely systolic and/or diastolic heart dysfunction. 
                  inotropiccompliance</Content>

我希望此内容在一行中,“功能障碍”一词之间没有空格。和结束标签“内容”。所以,它应该看起来像这样:

<Content>Two potential pathophysiologic conditions lead to the clinical findings of HF, namely systolic and/or diastolic heart dysfunction.</Content>

我认为在第一个转换之后我需要另一个 xslt 转换,一旦我得到“内容”标签,我就能以某种方式删除这个奇怪的间距。我尝试的是:

<xsl:template match="text()[parent::Content]" mode="li-pass1" priority="2">
         <xsl:value-of select="normalize-space(translate(., '&#160;', ' '))"/>
</xsl:template>

用这种方法我没有得到想要的结果。有人可以帮我解决这个问题吗?我将不胜感激,在此先感谢大家。

标签: xmlxsltindesign-server

解决方案


检查您使用的序列化方法 ( xsl:output method="?")。HTML 输出方法允许以这种方式换行长文本行,而 XML 输出方法则不允许。


推荐阅读