Carter Bailey Tech Thoughts, lessons learned, and motivation

21Jul/110

XML XSLT Quirk – Transformation Resulting in Extra Characters (Using C#)

Recently, I've been working with XML and XSLT transformations at work to build Continuity of Care Documents (CCD), and I thought I'd share a little quirk I came across. This might be one of those "duh" moments for most people, but I had to find out the hard way, so maybe this will help someone else out there.

I am creating an XmlDataDocument with a DataSet returned by an Oracle stored procedure, and then I am transforming it using an XslCompiledTransformation and XSLT file.

For code examples and results click "Continue Reading"

Here is a snippet of what I was originally using in the XSLT file:

1
2
3
4
5
6
<xsl:element name="telecom">
   <xsl:attribute name="use">WP</xsl:attribute>
   <xsl:attribute name="value">
      tel:<xsl:value-of select="WORKPHONE"/>
   </xsl:attribute>
</xsl:element>

And the resulting XML element:

<telecom use="HP" value="&#xA;              tel:(903) 555-5555" />

To make sure the extra character (&#xA;) and spaces aren't included in the value attribute of the XML element, put it all on one line in the XSLT file:

1
2
3
4
<xsl:element name="telecom">
   <xsl:attribute name="use">WP</xsl:attribute>
   <xsl:attribute name="value">tel:<xsl:value-of select="WORKPHONE"/></xsl:attribute>
</xsl:element>

This goes for creating attributes, but does not affect something like the following:

1
2
3
<state>
   <xsl:value-of select="STATE">
</state>

So if you are seeing extra characters or spaces in your final XML document, put it all on one line and see if that clears up your problem.

Posted by Carter Bailey

Comments (0) Trackbacks (0)

No comments yet.


Leave a Reply

No trackbacks yet.