I am completely new with XSLT, so don't mind me asking about the basic things. I need to prepare an xml which will be sent to Adobe InDesign server. In html files (which represent my input that I need to transform to xml and send to Adobe InDesign by using XSLT transformation), I've got the following list:
<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>
The main template that I am using for the transformation is:
<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>
I am getting the following output, with the unwanted spacing between BL and 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>
I am supposed to get the following output in 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>
So, the following line (taken from the output) is actually my issue:
<Content>Two potential pathophysiologic conditions lead to the clinical findings of HF, namely systolic and/or diastolic heart dysfunction.
inotropiccompliance</Content>
I wanted this content to be in one line, without the spacing between the word "dysfunction." and the closing tag "Content". So, it's supposed to look something like this:
<Content>Two potential pathophysiologic conditions lead to the clinical findings of HF, namely systolic and/or diastolic heart dysfunction.</Content>
I thought that I needed an another xslt transformation after the first one, and once I would get the "content" tags, I would be able to somehow remove this odd spacing. What I tried was:
<xsl:template match="text()[parent::Content]" mode="li-pass1" priority="2">
<xsl:value-of select="normalize-space(translate(., ' ', ' '))"/>
</xsl:template>
I didn't get a desired result with this method. Could someone help me with this problem? I would appreciate any help, thank you all in advance.
The line break is in the input between the li
start tag and the ul
start tag there is a text node that contains the line break and the indenting white space.
I think you rather want to use
<xsl:value-of select="(text() | descendant::span/text() | descendant::i/text())!normalize-space()"/>
instead of the copy-of. The !
operator is XPath/XSLT 3, if you only have XSLT/XPath 2 support you can use
<xsl:value-of select="(text() | descendant::span/text() | descendant::i/text())/normalize-space()"/>
value-of
has an optional separator
attribute but it defaults to the space so for your sample you don't need it, if I have understood correctly that you want the selected items to be separated by spaces.