我是 XSLT 世界的新手,提前感谢您的理解。我需要准备一个将发送到 Adobe InDesign 服务器的 xml。在 html 文件中,这是我需要转换为 xml 并使用 XSLT 转换发送到 Adobe InDesign 的输入,我有“li”元素,其中包含“span”标签和“i”(斜体)标签。我想将“i”标签处理为 InDesign 的最终 xml 中的斜体。我尝试通过以下 xslt 匹配“i”标签:
<xsl:template match="i" mode="process-text">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Italic">
<Content>
<xsl:copy-of select="text()"/>
</Content>
</CharacterStyleRange>
</xsl:template>
但没有结果。
例如,我有以下输入:
<li class="MsoNormal" style="mso-list:l0 level2 lfo1;tab-stops:list 1.0in">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>
我想将其转换为以下内容:
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/BL2">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">
<Content>Systolic dysfunction: an </Content>
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Italic">
<Content>inotropic</Content>
</CharacterStyleRange>
<Content> abnormality, due to myocardial infarction (MI) or dilated or ischemic cardiomyopathy (CM), resulting in diminished systolic emptying (ejection fraction <45%).</Content>
<Br/>
</CharacterStyleRange>
</ParagraphStyleRange>
我最初的问题是如何拆分“li”标签并(单独)处理其中的文本,以及如何通过 XSLT 分别处理“li”中的“span”和“i”标签?预先感谢您的任何帮助。
更新: 我的主要模板,“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}">
<xsl:choose>
<xsl:when test="descendant::i/text()">
<Content>
<xsl:copy-of select="./text() | descendant::span/text() "/>
</Content>
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Italic">
<Content>
<xsl:copy-of select="descendant::i/text()"/>
</Content>
</CharacterStyleRange>
</xsl:when>
<xsl:otherwise>
<Content>
<xsl:copy-of select="./text() | descendant::span/text() "/>
</Content>
</xsl:otherwise>
</xsl:choose>
</ParagraphStyleRange>
</xsl:template>
此模板以错误的方式影响最终的 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>
</CharacterStyleRange>
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Italic">
<Content>inotropiccompliance</Content>
</CharacterStyleRange>
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]"/>
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/BL2">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">
<Content>Systolic dysfunction: an abnormality, due to myocardial infarction (MI) or dilated or ischemic cardiomyopathy (CM), resulting in diminished systolic emptying (ejection fraction <45%).</Content>
</CharacterStyleRange>
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Italic">
<Content>inotropic</Content>
</CharacterStyleRange>
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]"/>
</ParagraphStyleRange>
因此,您可以看到,斜体元素位于单独的标签中,但没有其他内容。你能建议我需要做什么吗?