Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

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> 
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top