如何将新的 XSLT 转换应用到前一个的输出 - 列表之间的奇数间距问题?

How to apply a new XSLT transformation to the output of the previous one-a problem with odd spacing between the lists?

我对 XSLT 完全陌生,所以不要介意我问一些基本的问题。我需要准备一个 xml 发送到 Adob​​e InDesign 服务器。在 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 转换后进行另一个 xslt 转换,一旦我获得“内容”标签,我就能够以某种方式删除这个奇怪的间距。我尝试的是:

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

我用这个方法没有得到想要的结果。有人可以帮我解决这个问题吗?如果有任何帮助,我将不胜感激,提前谢谢大家。

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

换行符在 li 开始标签和 ul 开始标签之间的输入中有一个包含换行符和缩进白色 space 的文本节点。

我想你更想使用

<xsl:value-of select="(text() | descendant::span/text() | descendant::i/text())!normalize-space()"/>

而不是 copy-of。 ! 运算符是 XPath/XSLT 3,如果你只有 XSLT/XPath 2 支持你可以使用

<xsl:value-of select="(text() | descendant::span/text() | descendant::i/text())/normalize-space()"/>

value-of 有一个可选的 separator 属性,但它默认为 space 因此对于您的示例,您不需要它,如果我没有正确理解您想要选择用 spaces.

分隔的项目