[xsl] Preserving White Space in Immediate following-sibling

Subject: [xsl] Preserving White Space in Immediate following-sibling
From: "Joe Heidenreich" <HeidenreichJ@xxxxxxxx>
Date: Mon, 27 Jun 2005 14:24:33 -0400
I'm having a problem preserving white-space between two elements that
immediately follow each other. For example, I can have the following two
paragraphs in XML:

<p>Sentence 1.<xref ref-type="bibr" rid="b1">1</xref> Sentence 2. <xref
ref-type="bibr" rid="b2">2</xref> Sentence 3.</p>
<p>Sentence 1.<xref ref-type="bibr" rid="b1">1</xref> <xref
ref-type="fig" rid="F1">Figure 1</xref> continuation of Sentence 2 which
started with a reference.</p>

The first one will be translated correctly, but the second one ignores
the white space between the two xref tags so that the output is:
"Sentence 1.1Figure 1 continuation of Sentence 2 which started with a
reference."

I tried remedying my problem with the following XSLT:

<xsl:template match="xref">
  <xsl:if test="@ref-type = 'bibr'">
   <sup><a href="#{@rid}"><xsl:value-of select="."/></a></sup>
  </xsl:if>
  <xsl:if test="@ref-type = 'fig'">
   <a href="#{@rid}"><xsl:value-of select="."/></a>
  </xsl:if>
  <xsl:if test="following-sibling::*[1][self::xref]">&#xA0;</xsl:if>
 </xsl:template>

Which fixed my second paragraph, but altered my first paragraph by
adding an extra space after the first xref. I'm not exactly sure why the
white space in the second paragraph is being ignored initially. Is there
a way to write my code to see if there is any text in-between the xref
tags and if not add the space?


Joe Heidenreich
Programmer
heidenreichj@xxxxxxxx

Current Thread