xml - 如何将新的 XSLT 转换应用于前一个的输出 - 列表之间存在奇数间距的问题?
问题描述
我对 XSLT 完全陌生,所以不要介意我询问基本的事情。我需要准备一个将发送到 Adobe InDesign 服务器的 xml。在 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 <i>inotropic</i> abnormality, due to myocardial infarction (MI) or dilated or ischemic cardiomyopathy (CM), resulting in diminished systolic emptying (ejection fraction <45%).</li>
<li>Diastolic dysfunction: a <i>compliance</i> abnormality, due to hypertensive CM, in which ventricular relaxation is impaired (ejection fraction >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 <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 >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 <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 >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(., ' ', ' '))"/>
</xsl:template>
用这种方法我没有得到想要的结果。有人可以帮我解决这个问题吗?我将不胜感激,在此先感谢大家。
解决方案
检查您使用的序列化方法 ( xsl:output method="?"
)。HTML 输出方法允许以这种方式换行长文本行,而 XML 输出方法则不允许。
推荐阅读
- selenium-webdriver - 需要使用先前的节点子查找下一个节点 xpath
- x86-16 - 两个正数之和为负数
- python - Python 锁定异步套接字操作
- php - 用php转换嵌套数组中的普通数组
- c# - 是否有像 Queue 这样实现 IAsyncEnumerable 的 C# 类?
- linux - Armbian 无法运行脚本
- linux - 使用makefile中循环的值从不同的文件夹中读取
- javascript - 在带有装饰器和 HOC 的类组件中使用 react-i18next
- kotlin - 复杂层次结构的多态 kotlinx 序列化
- android - FLAG_INSISTENT 当另一个通知弹出时停止重复通知声音