0

I want all whitespace removed so my final code looks like a single block of text.

Here's my header

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"
doctype-public="-W3CDTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
omit-xml-declaration="yes"
encoding="UTF-8"
indent="no" />

which seems to work most of the time, but I am having issues. See source

The problematic area seems to be

<!-- clinical research coordinator -->
<xsl:template match="clinical-research-coordinators">

<xsl:variable name="id" select="item/@id" />
<xsl:variable name="entry" select="//people/entry[@id=$id]" />

<xsl:value-of select="$entry/display-name" />, 

clinical research coordinator, at 

<xsl:element name="a">

    <xsl:attribute name="href">mailto:<xsl:value-of select="$entry/email" /></xsl:attribute>
    <xsl:attribute name="class">email</xsl:attribute>

    <xsl:value-of select="$entry/email" />

</xsl:element>

or 

<xsl:value-of select="$entry/phone" />  

</xsl:template>

I am using Symphony CSM to generate the data. I just want all whitespace removed, but I want to keep my indentation patterns for readability.

Kirk Strobeck
  • 17,984
  • 20
  • 75
  • 114

2 Answers2

1

From http://www.w3.org/TR/xslt#strip

After the tree for a source document or stylesheet document has been constructed, but before it is otherwise processed by XSLT, some text nodes are stripped. A text node is never stripped unless it contains only whitespace characters.

This

",

clinical research coordinator, at

"

and

"
or

"

are not white space only text nodes, then they shouldn't be striped from the stylesheet.

That is why the xsl:text instruction is for. Use:

<xsl:text>, clinical research coordinator, at </xsl:text> 

and

<xsl:text> or </xsl:text> 
  • +1 thank you! I am commenting on the other answer, there's one last part to the problem. – Kirk Strobeck Dec 23 '10 at 20:12
  • @Kirk Strobeck: I think that is a different question. –  Dec 23 '10 at 20:21
  • @Kirk Strobeck: I don't understand what is the remainding question? –  Jan 04 '11 at 15:08
  • @Alejandro it was an accident, meant to put the bounty on another question :\ – Kirk Strobeck Jan 04 '11 at 16:33
  • @Kirk Strobeck: Then you can flag for moderators attention (Jeff Atwood [quote](http://meta.stackexchange.com/questions/14591/why-cant-we-close-questions-with-bounties/27103#27103)) –  Jan 04 '11 at 16:54
1

The problematic area seems to be

<!-- clinical research coordinator -->
<xsl:template match="clinical-research-coordinators">
    <xsl:variable name="id" select="item/@id" />
    <xsl:variable name="entry" select="//people/entry[@id=$id]" />
    <xsl:value-of select="$entry/display-name" />,   clinical research coordinator, at   
    <xsl:element name="a">
        <xsl:attribute name="href">mailto:
            <xsl:value-of select="$entry/email" />
        </xsl:attribute>
        <xsl:attribute name="class">email</xsl:attribute>
        <xsl:value-of select="$entry/email" />
    </xsl:element>
      or   
    <xsl:value-of select="$entry/phone" />
</xsl:template>

The solution is:

<!-- clinical research coordinator -->
<xsl:template match="clinical-research-coordinators">
    <xsl:variable name="id" select="item/@id" />
    <xsl:variable name="entry" select="//people/entry[@id=$id]" />
    <xsl:value-of select="$entry/display-name" />,   clinical research coordinator, at <xsl:text/>  
    <xsl:element name="a">
        <xsl:attribute name="href">mailto:
            <xsl:value-of select="$entry/email" />
        </xsl:attribute>
        <xsl:attribute name="class">email</xsl:attribute>
        <xsl:value-of select="$entry/email" />
    </xsl:element>
      <xsl:text> or </xsl:text>   
    <xsl:value-of select="$entry/phone" />
</xsl:template>

Do note: The use of the <xsl:text> instruction to eliminate existing whitespace characters and to explicitly specify what text exactly should be output.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431