You haven't explained which characters cause the problem, but I guess its the ones like & # 1 3 ;
 
What's happening here is that the XML parser is doing whitespace normalization. See section 3.3.3 of the XML Recommendation. This says that a newline, tab, or carriage return in an attribute value is replaced by a single space, unless it is written as a character reference.
 
I don't know why MSXML4 isn't doing the attribute value normalization, but I think it's wrong.
 
Michael Kay
-----Original Message-----
From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of Richard Patchet
Sent: 21 October 2003 15:22
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Entity vs. Character in XPath

I have a simple recursive template for trimming whitespace in an element. If in the test attribute of the <xsl:if> I use the actual character value, Saxon 6.5.3 does not match, but if I use the entity reference for the character, Saxon matches. MSXML works with both.
 
Input data:
 
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="trim_test.xslt"?>
<Test>
  <connectorInfo>
    <username> 
UserName</username>
    <effectiveUsername> 
UserName</effectiveUsername>
  </connectorInfo>
</Test>
Stylesheet:
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1" exclude-result-prefixes="xsl">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="/">
    <xsl:element name="Test">
      <xsl:element name="connectorInfo">
        <xsl:element name="username">
          <xsl:variable name="ltrim_chars1-1">
            <xsl:call-template name="ltrim_chars">
              <xsl:with-param name="ltrim_chars-in" select="/Test/connectorInfo/username"/>
            </xsl:call-template>
          </xsl:variable>
          <xsl:value-of select="$ltrim_chars1-1"/>
        </xsl:element>
        <xsl:element name="effectiveUsername">
          <xsl:variable name="ltrim_ents2-2">
            <xsl:call-template name="ltrim_ents">
              <xsl:with-param name="ltrim_ents-in" select="/Test/connectorInfo/effectiveUsername"/>
            </xsl:call-template>
          </xsl:variable>
          <xsl:value-of select="$ltrim_ents2-2"/>
        </xsl:element>
      </xsl:element>
    </xsl:element>
  </xsl:template>
  <xsl:template name="ltrim_chars">
    <xsl:param name="ltrim_chars-in"/>
    <xsl:choose>
      <xsl:when test="substring($ltrim_chars-in, 1, 1)=' ' or substring($ltrim_chars-in, 1, 1)=' ' or substring($ltrim_chars-in, 1, 1)='
' or substring($ltrim_chars-in, 1, 1)='
'">
        <xsl:variable name="one-less-left">
          <xsl:call-template name="ltrim_chars">
            <xsl:with-param name="ltrim_chars-in" select="substring($ltrim_chars-in, 2)"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:value-of select="$one-less-left"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$ltrim_chars-in"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
    <xsl:template name="ltrim_ents">
        <xsl:param name="ltrim_ents-in"/>
        <xsl:choose>
            <xsl:when test="substring($ltrim_ents-in, 1, 1)=' ' or substring($ltrim_ents-in, 1, 1)='&#9;' or substring($ltrim_ents-in, 1, 1)='&#10;' or substring($ltrim_ents-in, 1, 1)='&#13;'">
                <xsl:variable name="one-less-left">
                    <xsl:call-template name="ltrim_ents">
                        <xsl:with-param name="ltrim_ents-in" select="substring($ltrim_ents-in, 2)"/>
                    </xsl:call-template>
                </xsl:variable>
                <xsl:value-of select="$one-less-left"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$ltrim_ents-in"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:transform>
Saxon 6.5.3 output:
 
<?xml version="1.0" encoding="UTF-8"?>
<Test>
  <connectorInfo>
    <username>
UserName</username>
    <effectiveUsername>UserName</effectiveUsername>
  </connectorInfo>
</Test>
MSXML 4.0 output:
 
<?xml version="1.0" encoding="UTF-8"?>
<Test>
<connectorInfo>
<username>UserName</username>
<effectiveUsername>UserName</effectiveUsername>
</connectorInfo>
</Test>
I do not understand why the character should be treated differently than the entity reference in Saxon.
 
Richard Patchet
bTrade, Inc.
2324 Gateway Drive
Irving, TX 75063
972-5802981
www.bTrade.com