我是 XSLT 的新手,提前感谢您的理解。我需要准备一个将发送到 Adobe InDesign 服务器的 xml。在 html 文件(代表我需要转换为 xml 并使用 XSLT 转换发送到 Adobe InDesign 的输入)中,我有以下列表:
<li>IV <span><span>nitroglycerin</span></span> may be of short-term benefit by decreasing preload and afterload by dilating peripheral capacitance and resistance vessels on vascular smooth musculature (IV 10 to 20 <i>μ</i>g/min, increase up to 200 <i>μ</i>g/min) <span>1</span><span>B</span>.</li>
我用于转换的主要模板是:
<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:value-of select="(text() | descendant::span/text() | descendant::i/text())/normalize-space()"/>
</Content>
<Br/>
</ParagraphStyleRange>
</xsl:template>
但是有了这个解决方案,我得到了这个不需要的效果:
<Content>IV nitroglycerin may be of short-term benefit by decreasing preload and afterload by dilating peripheral capacitance and resistance vessels on vascular smooth musculature (IV 10 to 20 μ g/min, increase up to 200 μ g/min) 1 B .</Content>
因此,每个“i”或“span”标签(来自输入)都会创建一个新的间距,例如,它不应出现在“μg”或“1B”中的字符之间。我可能需要以某种方式重写我的选择,对吧?我想选择descendant-or-self::*/text(),但我不想包括descendant::li。我不知道该怎么做。
所需的输出如下:
<Content>IV nitroglycerin may be of short-term benefit by decreasing preload and afterload by dilating peripheral capacitance and resistance vessels on vascular smooth musculature (IV 10 to 20 μg/min, increase up to 200 μg/min) 1B.</Content>
预先感谢您的任何帮助。
更新: 让我更好地解释这个问题。这是我需要转换的输入列表:
<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>
我得到的是:
<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. inotropic compliance</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>
</ParagraphStyleRange>
期望的结果不应该在“italic”和“span”标签之间包含额外的间距(例如“inotropic”和“compliance”)。而且,我不想在文中使用“正性肌力”和“顺从性”词:“两种潜在的病理生理条件导致 HF 的临床发现,即收缩和/或舒张性心脏功能障碍。正性肌力顺应性”,因为那些来来自“li”元素的后代,不属于第一个“li”。所以,我想得到的是:
<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>
</ParagraphStyleRange>
再次感谢您的帮助。