繁体   English   中英

如何将新的 XSLT 转换应用到上一个的 output 列表之间的奇数间距问题?

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

我对 XSLT 完全陌生,所以不要介意我询问基本的事情。 我需要准备一个 xml 将发送到 Adobe InDesign 服务器。 在 html 文件(代表我需要转换为 xml 并使用 XSLT 转换发送到 Adobe 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>

我得到以下 output,在 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 中得到以下 output:

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

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

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

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

我想你宁愿使用

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

而不是副本。 ! 运算符是 XPath/XSLT 3,如果您只有 XSLT/XPath 2 支持,您可以使用

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

value-of有一个可选的separator属性,但它默认为空格,因此对于您的示例,如果我正确理解您希望所选项目用空格分隔,则不需要它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM